Jump to content

Talis

Members
  • Posts

    7
  • Joined

  • Last visited

Files posted by Talis

  1. Free

    Script command: Dynprompt

    Works like prompt(), but lets you specify return values by adding a pipe symbol.
    Examples:
    dynprompt("Menu Entry");
    Return Value: 1
    @menu: 1
    @menustr$: Menu Entry
    @menunum: 1
    dynprompt("^EE0000Menu Entry^000000|Test");
    Return Value: 1
    @menu: 1
    @menustr$: Test
    @menunum: 1
    dynprompt("Shazam|5 Shazam");
    Return Value: 5
    @menu: 1
    @menustr$: 5 Shazam
    @menunum: 5
    Script example:
    // Dynprompt usage - Advanced example// Probably the best way to use thisfunction script dynprompt_sample3 { // The real power of dynprompt is that you can specify the return value for each menu element. // The return value is a atoi of the string following the pipe | - the full string can be accessed through @menustr$ // The atoi val can also be accessed through @menunum // If you want to use both number & string, the number has to come first else atoi won't work // Use the pipe character | to denote the return value - best to work with numbers, but strings work as well set .@menu$[0], "^009900Hello!^000000|1Hello"; set .@menu$[1], "^0000EEInfo~^000000|2Info"; set .@menu$[2], "^222222Test.^000000|3Test"; // This time we'll just add a element based on a condition if(.@somecondition) set .@menu$[3], "^EE0000- Admin -^000000|4Admin"; set .@menu$[4], "^990099G'bye^000000|5Bye"; // Lets implode & switch/case switch(dynprompt(implode(.@menu$, ":"))) { case 1: mes "Oh, Hello to you too!"; break; case 2: mes "You want info? How about the time?"; mes gettimestr("%Y-%m/%d %H:%M:%S",21); mes "Also, you selected option #" + @menu; // @menu still works break; case 3: mes "Debug info:"; mes "@menu is " + @menu; mes "@menustr$ is " + @menustr$; mes "@menunum is " + @menunum; break; case 4: mes "Wow, a admin!"; break; case 5: mes "Bye bye~"; break; case 255: // Cancel button mes "Hey, don't ignore me!!"; break; } close;}
    I havn't tested it yet in production, but so far I havn't been able to encounter any issues with it.
    Also, I do all my eAthena devving on a windows box so I can't guarantee that it'll work with linux.
    Performance of dynprompt is going to be naturally worse than prompt, select or menu, but it might perform equally well in a dynamic setting if you take into consideration the array looping usually required - but I have not yet done any benchmarking or anything, so don't take my word for it. ( and to be honest, being able to create super clean code using switch / case is worth a tiny performance hit for me )
    I hope it will make your scripting less painful - it sure has for me!

    33 downloads

    Submitted

×
×
  • Create New...