Jump to content
  • 0

Wondering if it was possible to use a forloop to define cases.


Question

Posted (edited)

Just wondering it was possible to do something like this, instead of defining cases indifidually. I am currently unable to test, hence I'm asking.

switch(select(
 "Start from Beggining ["+.lifecost[0]+"]:"+
 ((.unlock && @lives > .lifecost[1])?"Start from flag 1 ["+.lifecost[1]+"]:":":")+
 ((.unlock > 1 && @lives > .lifecost[2])?"Start from flag 2 ["+.lifecost[2]+"]:":":")+
 ((.unlock > 2 && @lives > .lifecost[3])?"Start from flag 3 ["+.lifecost[3]+"]:":":")+
 "Quit")
 )
 for(set .@i,1; .@i < 5, set .@i, .@i+1) {
  case .@i:
set @lives,@lives-.lifecost[(.@i-1)];
atcommand "@alive "+strcharinfo(0);
dispbottom "You have "+@lives+" Lives left";
warp "hellfire",.hellwarp[.@i],.Hellwarp[.@i+1];
break;

edit:

There we go.

Edited by garet999
  • Upvote 1

2 answers to this question

Recommended Posts

Posted

cannot

script error on npc/zzz.txt line xxxx
parse_syntax: 'case' label not integer

and correct way to do this .... switch..case not even needed

whenever the script parse *select, *prompt or *menu

and the player selected the option

will return @menu variable

... can read further on *menu inside script_commands.txt

select "start from beginning ... ",
( condition 1 )? " <statement 1 >" : "" ,
( condition 2 )? " <statement 2 >" : "" ,
( condition 3 )? " <statement 3 >" : "" ,
set @lives, @lives - lifecost[ @menu ];
....
warp "hellfire", .hellwarpx[ @menu ], .hellwarpy[ @menu ];
...

select "1", "", "3";

will show up only 2 options , but select the "3" will still return @menu = 3

leaving the option as "" will not show up in the selection, but the variable still retains the counter of options correctly

  • Upvote 1
Posted (edited)

Interesting; I didn't know select returned an @menu variable. I really should read the manual lmao.

found it

'This function is a handy replacement for 'menu' for some specific cases where

you don't want a complex label structure - like, for example, asking simple yes-

no questions. It will return the number of menu option picked, starting with 1.

Like 'menu', it will also set the variable @menu to contain the option the user

picked.'

Edited by garet999

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