Jump to content
  • 0

Array Confusion


Pavi

Question


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  10
  • Reputation:   0
  • Joined:  03/03/12
  • Last Seen:  

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$);

Link to comment
Share on other sites

7 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  379
  • Reputation:   304
  • Joined:  11/10/11
  • Last Seen:  

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  10
  • Reputation:   0
  • Joined:  03/03/12
  • Last Seen:  

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

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$);

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  10
  • Reputation:   0
  • Joined:  03/03/12
  • Last Seen:  

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;

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

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.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  40
  • Topics Per Day:  0.01
  • Content Count:  587
  • Reputation:   104
  • Joined:  11/19/11
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

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

Link to comment
Share on other sites

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.

×
×
  • Create New...