Jump to content
  • 0

Array Confusion


Question

Posted

Hey guys,just messing around with arrays right now,and for some reason my menu won't come up(Well it comes up,but there are no options within it) when I tried making it dynamic,this is actually my first array used menu,so I'm a lil' lost,does anyone know what I'm doing wrong?

setarray @cities$[0],"Morocc","Alberta","Izlude","Lutie","Comodo","Yuno","Amatsu","Gonryun","Umbala","Niflheim","Louyang","Jawaii","Ayothaya","Einbroch","Lighthalzen","Einbech","Hugel","Rachel","Veins","Moscovia";
for(set .@n,0; .@n<getarraysize(@cities$); set .@n, .@n+1)
{
set .@selectcity$[.@m],@cities$[.@n];
set .@m,.@m+1;
}
set @selectmenu$,getarraysize(.@selectcity$[0]);
for(set .@i,1; .@i <getarraysize(.@selectcity$); set .@i,.@i+1)
set @selectmenu$, @selectmenu$+":"+.@selectcity$[.@i];
select(.@selectmenu$);

7 answers to this question

Recommended Posts

Posted

Hmm.

The weird error is here:

set @selectmenu$,getarraysize(.@selectcity$[0]);

What are you trying to do ?

You can do the same script in two lines:

setarray @cities$,"Morocc","Alberta","Izlude","Lutie","Comodo","Yuno","Amatsu","Gonryun","Umbala","Niflheim","Louyang","Jawaii","Ayothaya","Einbroch","Lighthalzen","Einbech","Hugel","Rachel","Veins","Moscovia";
select( implode( @cities$, ":" ) );

I keep the use of the @var since I don't know what you want to do with, but in this concept it's better to use .@var

Posted

I was just trying to get all the variables in the array to print out in a menu,so I didn't have to put them all in one one by one by myself xD

Posted

As KeyWorld posted, the implode() command is the best if you're not adding in any new text to your arrays. If you wanted to include, say, map player count (you'd also have to change the map name cases, though, this is just an example~), you would have to use a loop.

setarray .@maps$[0],"morocc","alberta","izlude","xmas","comodo";
for(set .@i,0; .@i<getarraysize(.@maps$); set .@i,.@i+1)
   set .@menu$, .@menu$+.@maps$[.@i]+" ("+getmapusers(.@maps$[.@i])+"):";
select(.@menu$);

Posted

As KeyWorld posted, the implode() command is the best if you're not adding in any new text to your arrays. If you wanted to include, say, map player count (you'd also have to change the map name cases, though, this is just an example~), you would have to use a loop.

setarray .@maps$[0],"morocc","alberta","izlude","xmas","comodo";
for(set .@i,0; .@i<getarraysize(.@maps$); set .@i,.@i+1)
set .@menu$, .@menu$+.@maps$[.@i]+" ("+getmapusers(.@maps$[.@i])+"):";
select(.@menu$);

Is there no way to make it similiar to a switch(select(

For instance,if they did pick the "Morocc":


setarray .@maps$[0],"morocc","alberta","izlude","xmas","comodo";
for(set .@i,0; .@i<getarraysize(.@maps$); set .@i,.@i+1)
   set .@menu$, .@menu$+.@maps$[.@i]+" ("+getmapusers(.@maps$[.@i])+"):";
switch(select(.@menu$)){
case 1:
next;
mes "You've select Morocc";
close;

Posted

A switch is perfectly fine too. o: All that select() returns is the nth menu option you chose (starting at 1), which you can easily attach a switch to.

Posted (edited)

As Euphy mention ,,just change the start index of array and loop, It should work.

setarray .@maps$[1],"morocc","alberta","izlude","xmas","comodo";

for(set .@i,1; .@i<=getarraysize(.@maps$); set .@i,.@i+1)

------------------------------------------------------------------------------------------------------

edit : thx Euphy for <=

Edited by QQfoolsorellina
Posted

@QQfoolsorellina: You'd have to change it to <= then. :3 Anyhow, I think it's generally the standard to write "select(.@menu$)-1" instead of skipping an array value, but that doesn't really matter much (or at all).

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...