Jump to content
  • 0

Cases in Arrays


iFoxkun

Question


  • Group:  Members
  • Topic Count:  24
  • Topics Per Day:  0.01
  • Content Count:  189
  • Reputation:   16
  • Joined:  11/20/11
  • Last Seen:  

gm02,96,99,4 script Professor Oak 793,{


mes "Hello, Welcome to the world of Pokemon";
next;
mes "We, Pokemon Trainers, reside in this world in peace with Pokemon";
next;
mes "Which starter Pokemon do you wish to have?";
set .@menu, select(.pkmn_menu$) -1;
if(.pkmn_menu$[0] == .pkmn$[0]):
mes "You choose " +.pkmn$[0]+ "?";

OnInit:
setarray .pkmn$,"Bulbasaur","Charmander","Squirtle";
for ( set .@i, 0; .@i < getarraysize(.pkmn$); set .@i, .@i +1 )
setarray .pkmntype$,"Grass","Fire","Water";
for ( set .@i, 0; .@i < getarraysize(.pkmntype$); set .@i, .@i +1 )
set .pkmn_menu$, .pkmn_menu$ + (.pkmn$[.@i]) + " - " + (.pkmntype$[.@i]) +":";
}

The one text bolded, How do i make it, if a player selects option 1, Bulbasaur, it says something?

This one : if(.pkmn_menu$[0] == .pkmn$[0]):

Edited by iFoxkun
Link to comment
Share on other sites

4 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  130
  • Reputation:   43
  • Joined:  12/11/11
  • Last Seen:  

The decrement of .menu was if it was supposed to index an array (since arrays start their indexing at 0, not 1). Using it with switch, which itself can handle whatever order you choose, you don't want to '-1'.

set .menu, select(.pkmn_menu$) -1;

Would make your first choice 0, then you check for 'case 1' which wants a 1. Solved by not having '-1'.

You do not terminate the script with a 'close;'. It will therefore continue after the menu down to the OnInit once again and continue to build the menu.

It's always good coding standard to make sure that an 'end' or 'close' is placed at the end of the NPC, but before On<Event> labels, in case you miss to terminate the user somewhere on the way.

Edited by plankt
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  130
  • Reputation:   43
  • Joined:  12/11/11
  • Last Seen:  

'select' returns an index for the selection the user made.

1 for the first alternative, 2 for the second and so on... (or if it begins on 0, can't remember)

You can just use that to index the correct pokemon in the .pkmn$ array: (-1 if it starts on 1, since arrays count from 0)

if( .pkmn$[.@menu-1] == "Bulbasaur" ) ...

Or if you don't want to go for names, use the index directly:

switch( .@menu ){
case 1:
Bulbasaur code
break;
case 2:
Charmander code
break;
case 3:
Squirtle code
break;
}

You only need one for loop in the OnInit aswell:

OnInit:
setarray .pkmn$,"Bulbasaur","Charmander","Squirtle";
setarray .pkmntype$,"Grass","Fire","Water";
for ( set .@i, 0; .@i < getarraysize(.pkmntype$); set .@i, .@i +1 )
set .pkmn_menu$, .pkmn_menu$ + (.pkmn$[.@i]) + " - " +...

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  24
  • Topics Per Day:  0.01
  • Content Count:  189
  • Reputation:   16
  • Joined:  11/20/11
  • Last Seen:  

'select' returns an index for the selection the user made.

1 for the first alternative, 2 for the second and so on... (or if it begins on 0, can't remember)

You can just use that to index the correct pokemon in the .pkmn$ array: (-1 if it starts on 1, since arrays count from 0)

if( .pkmn$[.@menu-1] == "Bulbasaur" ) ...

Or if you don't want to go for names, use the index directly:

switch( .@menu ){
case 1:
Bulbasaur code
break;
case 2:
Charmander code
break;
case 3:
Squirtle code
break;
}

You only need one for loop in the OnInit aswell:

OnInit:
setarray .pkmn$,"Bulbasaur","Charmander","Squirtle";
setarray .pkmntype$,"Grass","Fire","Water";
for ( set .@i, 0; .@i < getarraysize(.pkmntype$); set .@i, .@i +1 )
set .pkmn_menu$, .pkmn_menu$ + (.pkmn$[.@i]) + " - " +...

I tried the second option. The case 1 etc doesn't work and when I close it, the menu option multiplies:


gm02,96,99,4 script Professor Oak 793,{


mes "Hello, Welcome to the world of Pokemon";
next;
mes "We, Pokemon Trainers, reside in this world in peace with Pokemon";
next;
L_SelectPkmn:
mes "Which starter Pokemon do you wish to have?";
set .menu, select(.pkmn_menu$) -1;
switch( .menu ) {
case 1: 
next;
mes "You choose " +.pkmn$[0]+ "?";
if(select("Yes:No")==2) goto L_SelectPkmn;


}
OnInit:
setarray .pkmn$,"Bulbasaur","Charmander","Squirtle";
setarray .pkmntype$,"Grass","Fire","Water";
for ( set .@i, 0; .@i < getarraysize(.pkmn$); set .@i, .@i +1 ) 
set .pkmn_menu$, .pkmn_menu$ + (.pkmn$[.@i]) + " - " + (.pkmntype$[.@i]) +":";
}

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  24
  • Topics Per Day:  0.01
  • Content Count:  189
  • Reputation:   16
  • Joined:  11/20/11
  • Last Seen:  

YES <333 THANK YOUUUU :D xD. I forgot i put a -1 there -.-. SO STUPID HUH? xD

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