Checking boolean and numerical variables

I am trying to check a 2-part conditional, 1 a true/false boolean, and the other a numerical value. So, if x is true and y is equal to 4.

I’m writing that as

*if (x) and (y=4) 

and it isn’t seeming to work. How should this be written?

What’s the result of this? Are you getting an error or is the text just not showing?

If the text isn’t showing, are you sure the variables are getting set correctly? Because what you wrote seems to work for me - I did this:

*temp x true
*temp y 4
It's ${x} and ${y};
*if (x) and (y=4)
	it works!
	*goto final
	it doesn't work!
	*goto final
*label final

And it printed “It’s true and 4; it works” like it was supposed to.

The error I’m getting is:
longdesc line 749: Invalid expression at char 36, expected no more tokens, found: EQUALITY [=]

*if ((x) and (y = 4))

And–just in case–the answer to a question you may have tomorrow,

*if (((x) and (y = 4)) and (promdate = “Robin”))


Seconding the above, what Gower wrote here should do the trick.

A good rule of thumb is that whenever you use a binary operator (and, or, +, *, etc.) with two inputs X and Y, you should enclose the two operands in a pair of parentheses. So, for example,

(X and Y)
(X or Y)

if X and Y are boolean expressions, and

(X + Y)
(X * Y)
(X / Y)

if X and Y are numerical expressions.

So the error I’m getting now is:
longdesc line 750: Invalid expression at char 37, expected CLOSE_PARENTHESIS, was: EQUALITY [=]

For reference, I have this written as

*elseif ((eyebrowdesc ) and (eyebrowdescroll2=2))
	*set eyebrows "straight"

What this should be doing is checking to see whether a random roll landed on 1, which sets whether you have a specific descriptor for eyebrows, and then if so, having a second roll, eyebrowroll2 actually setting a descriptor for the eyebrows, straight in this case.

Essentially, the endgoal is having a character builder that lets you preselect every element of your character’s appearance, having an option to select from a list of pre-generated characters, and then the option I’m actually trying to get working, having a randomiser that generates characters based on the possibilities. Its frustrating, because most of this is working very well.

Is eyebrowsdescroll2 a number and eyebrowsdesc a boolean?

Yes, eyebrowdesc is a boolean and eyebrowdescroll2 is a number. Eyebrowdescroll1 determines whether eyebrowdesc is set to true or false.

*rand eyebrowdescroll1 1 2 
*rand eyebrowdescroll2 1 6 
*if eyebrowdescroll1=1
  *set eyebrowdesc true
  *set eyebrowdesc false
*if ((eyebrowdesc) and (eyebrowdescroll2 = 1))
	*set eyebrows "arched" 
*elseif ((eyebrowdesc ) and (eyebrowdescroll2=2))
	*set eyebrows "straight"

I could be wrong, but it looks you have a space between eyebrowdescroll and the number 2 in your second *rand statement. So maybe eyebrowdescroll2 isn’t getting actually set to a number properly?

I’d just typed that out to show what I was doing, but I double checked and that isn’t the case in my startup or longdesc file. Thanks though.

Try removing eyebrowdesc from both checks and see what happens. Maybe it helps you narrow down the error.

*if eyebrowdescroll2 = 1

Ack, no problem. Wish I could help more, I’m genuinely not sure what the error is.

Best of luck!

You were very correct, Gower, that did end up saving me later down the road. thank you.

The problem actually seems to have been that elsewhere, I had a chunk of code that was setting a variable to false when its default value was was already false. Had nothing to do with that part of the code at all, but at least its working now

1 Like

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the @moderators.