Jump to content
  • 0

Help: dynamic switch(select)


Question

Posted

Hi,

 

Can anyone help me to make this bit of code work?


deletearray .@JSName$[0],getarraysize(.@JSName$[0]);

 

    for(set .@i,1; .@i < 13 ; set .@i,.@i+1){ ///// This generates a list with Job Names.


        setarray .@JSName$[.@i], jobname(.@i);


    }


mes .@npc$,$sep$,"Select an option."; next; for(set .@i,0; .@i < (getarraysize(.@JSName$[0])) ; set .@i,.@i+1){ /////<<<-- Need Help! switch(select(( implode( .@JSName$, ":" ) ))) { case (.@i): mes .@JSName$[.@i] close; }

I want to make a dynamic switch(select) with dynamic choices.

 

When I try to run the script, the server says:

 

script error on npc/custom/ORO/Functions/Jobs.txt line 65
    parse_syntax: expected '{'
    60 :        next;
    61 : for(set .@i,0; .@i < (getarraysize(.@JSName$[0])) ; set .@i,.@i+1)
{
    62 :        switch(select(( implode( .@JSName$, ":" ) )))
    63 :
    64 :
*   65 :                                        'c'ase (.@i):
    66 :                                                mes .@JSName$[.@i]
    67 :                                                close;
    68 :
 

 

Any help will be apreciated.

 

Thanks in advance.

1 answer to this question

Recommended Posts

Posted (edited)

You can't use variables in a case condition.

you could do case 1, case 2, case 3... etc

Or:

mes "Select a name from the menu below.";
if(select(implode(.@JSName$,":")))
	mes "Alright "+.@JSName$[@menu]+" it is then!";

 

You don't need the for loop because the tmp character variable @menu is populated by select() starting at 1.

so if you set your array like

setarray .@JSName$[1],"Mike","Scott","Phillip","Jesus";

@menu lines up with the players selection.

You can then access the values by an if statment or whatever.

if(!@menu-4) {mes "I think Jesus is great too!!";}

Anyways I hope this example helps you a little.

 

Edit: Editor Keeps breaking up my tabs -.-*

Edited by Skorm
  • Upvote 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...