I have been using switch statements to use passages multiple times. where you click next it goes blank and goes to a new screen but its the same passage. I know you can do the same thing with elseif statement’s but I have no clue how to do that. I know it is much more versatile than switch statements are. Any help would be much appreciated.
Hi!
It would be helpful if you could share the code you currently have in the passage with the <<switch>> macro, as well as the link bringing the player to that passage.
This way, we could be able to assess what could have gone wrong, and give you a solution!
You can use the </> symbol in the text editor of the forum to showcase the code in the post.
So, at some point it works, but the next time it does not work? It looks like the variable you’re basing your <<switch>> on has been updated and the new value is not recognized in any <<case>>. When you use a <<switch>> you might want to use a <<default>> to avoid this blank state.
Using the following (slightly modified) example from the <<switch>> documentation as a starting point…
<<switch $hairColor>>
<<case "red" "auburn">>
You ginger.
<<case "black" "brown">>
Dark haired, eh?
<<case "blonde">>
You may have more fun.
<<default>>
That's an unexpected colour!
<</switch>
…the <<if>> family of macro equivalent would look something like…
<<if $hairColor is "red" or $hairColor is "auburn">>
You ginger.
<<elseif $hairColor is "black" or $hairColor is "brown">>
Dark haired, eh?
<<elseif $hairColor is "blonde">>
You may have more fun.
<<else>>
That's an unexpected colour!
<</switch>
note: The <<default>> child tag was added to the <<switch>> example so the <<else>> equivalent could be demonstrated.
<<if ndef $textGroup>><<set $textGroup = 1>><</if>><<switch $textGroup>>
<<case 1>>Initial story text.
<<link "Link Text 1" `passage()`>><</link>>
<<case 2>>Next story text.
<<link "Link Text 2" `passage()`>><</link>>
<<default>>Final story text.
<<unset $textGroup>>[[Next Passage]]
<</switch>><<if def $textGroup>><<set $textGroup += 1>><</if>>
This is the switch code I used. nothing wrong with it but i was told the elseif statements could do more than the switch statements could. right now im just doing straight kinetic novels but i want to be able to do stuff like inventory and stats and map systems and dont think it would be possible with switch. not sure if i did this post right i have no clue how to do it. sorry if its wrong. The link i use is usually [[Home|home]]
There is nothing wrong with the <<switch>> macro.
Like Greyelf showed, the <<if>> macro is just able to do more complex conditional statements than <<switch>>. Whether you use <<switch>> or <<if>> depends on your need. <<switch>> is sometimes nicer to use if you have a bunch of conditions for one variable, but don’t want to write every time $var is [value] for each new <<elseif>> statement.
In your current case, asuming you are only using one variable, either macro is fine
For more complex interaction/system, the <<if>> macro will be better indeed.
You should check the documentation Greyelf linked on his post
I think I get the basic idea of it. I already have a basic corruption stat system in place. Working on a check system now. I’ll see how it goes. Thanks for the help.