Issues with boolean variables in functions

ShadowsEdge19
20 Mar 2022, 14:58

I'm trying to just assign a boolean to a locally created boolean variable inside of a function and use it but I keep getting errors saying its an unknown object. I am not sure whether I've missed a specific syntax somewhere on the IF statement line later on even though I've given it a default of true already to establish it's type.

Error running script: Error compiling expression 'bShowScene': Unknown object or variable 'bShowScene'

<function name="SceneSelector_AskHim" parameters="player"><![CDATA[
	
	roomObj = NPC1.parent 
	
    bShowScene = true
	if (roomObj.name= "Room1") {
		ShowMenu ("Yes? Can I help you with something?", NPC1.Room2Topics, false) {
			switch (result) {
				case ("Can I watch?") {
					player.sceneid = "CANWATCH"
				}
				case ("Can I give you something?"){
					player.sceneid = "GIVESOMETHING"
				}
				case ("Nevermind") {
					bShowScene = false
				}
			}	
			if (bShowScene) {
			msg ("DEBUG - Show " + player.sceneid + " Scene? - " + bShowScene)
			}			
		}
	}
	else {
		ShowMenu ("What do you want to know about?", NPC1.Room1Topics, false) {
			switch (result) {
				case ("About him") {
					player.sceneid = "ABOUTHIM"
				}
				case ("About you") {
					player.sceneid = "ABOUTYOU"
				}
				case ("Nevermind") {
					bShowScene = false
				}
			}

			if (bShowScene) {
				msg ("DEBUG - Show " + player.sceneid + " Scene? - " + bShowScene)
			}
		}
	}

]]></function>

mrangel
20 Mar 2022, 17:48

I've given it a default of true already to establish it's type.

The ShowMenu function displays a menu on the screen, and stores a script block to be run next turn if a menu item is clicked on. It doesn't run this turn; so has no access to the local variables of the script that created it.

Giving the variable a default value needs to be done inside the ShowMenu block.


ShadowsEdge19
20 Mar 2022, 18:13

So in turn 1 you call ShowMenu() and it displays options to select but when you do select one it's actually turn 2? Interesting.

Looks like it resolved my issue, thank you.