Conditional If statements in msg () issues

I've been experimenting with writing some complex chunk of inside of a single msg () but with optional attributes giving the flavour of the text conditional upon various settings but I'm coming short on certain uses of boolean type variable attributes and other special characters being used.

For instance if you use this:

msg ("if player.ishungry=true:Player is hungry} )

it won't work, but if you put this:

msg ("{if player.ishungry=True:Player is hungry} ")

This one works. Notice that the boolean has to be capital case and not solid lower case.

I'm also trying to do complex sentences with . and , in it but I keep getting this error message

msg ("{if player.ishungry=True:Man, this Player is hungry.} ") >>> "SyntaxError: Unexpected character: "Line: 1, Column: 1"

I also want to try and do else statements without having to do the following:

msg ("{if player.ishungry=True:Player is hungry}{if player.ishungry=False:Player is not hungry}")

Is there any specific documentation around If conditional text?


This one works. Notice that the boolean has to be capital case and not solid lower case.

If you use =, both values are converted to strings before being compared.
But why are you even using a boolean in that case? Without an operator, if just tests if the given value istrue, so {if player.ishungry:Player is hungry} does exactly the same thing.

I'm also trying to do complex sentences with . and , in it but I keep getting this error message

That should not happen, and the exact same line in a test game works fine for me. I think something else is causing your error.

I also want to try and do else statements without having to do the following:

You mean like {either player.ishungry:Player is hungry:Player is not hungry}?

(Note: {either doesn't use the restricted and unreliable rules {if does for parsing its expressions - the condition is a normal Quest expression, so you can use anything you'd put in as the expression for an if statement in your main code. This means that you can use your own functions inside the condition, but it does mean that you can't use attributename as a shorthand for game.attributename, and you need to include quotes if you want to compare some attribute to a string)

In your particular example, I would probably use:

msg ("{either GetBoolean(player, \"ishungry\"):Player is hungry:Player is not hungry}")

so that if the attribute hasn't been created yet, it's treated as false. I don't know if that's possible in your game in particular, but it's a good habit to get into so that you don't need to be so careful about setting every possible flag to false initially.


So for a string attribute type do I need to do the following?

msg ("{if GetString(player, \"fooditem"\)=Cake:Player eats cake}")

Can you do a Switch type for this instead of {either} for multiple food items?

As for the special character issue I'll see what happens once I try out the {either and GetBoolean() and GetString() methods to see if its resolved this issue.


So for a string attribute type do I need to do the following?

Sadly, there isn't a "clean" way to check if a string is undefined like there is for booleans (GetString still returns null if the attribute doesn't exist, so comparing it to a string would be an error.

You could use:

msg("{either HasString(player,\"fooditem\") and GetString(player,\"fooditem\")=\"Cake\":Player  likes cake.}")

which tests if the attribute exists and has the specified value (if it doesn't exist, there's no error because the second check isn't attempted.

Note that you can only do this with {either, because {if can't use functions in the condition.
That's one of the reasons I only use either in the text processor.


What if I need to do a NOT case, will that work as expected?

msg ("{either GetBoolean(player, "ishungry"):Player is hungry:Player is not hungry}")
msg ("{either NOT GetBoolean(player, "ishungry"):Player is not hungry:Player is hungry}")


Yes, that should work fine. {either can use any valid expression.

Oh… with regard to unspecified attributes, you can also use {either Equal(player.fooditem, \"Cake\"):The player likes cake}. I forgot about that for a moment; the Equal function tests if two values are the same type and are equal. I forgot about that when writing my last response.


Can I nest {either within the conditional response of another {either statement?


Yes :) That should work fine.

For some reason (I have no idea why), you might find that it also recognises {either player.someflag:It's true!|It's false!} works – it can use a | instead of a : before the 'else' clause. I have no idea why it works like this. If both are present, it will use the colon.

(also, if your text includes an actual colon, you can use : to avoid the text processor mistaking it for a part of the message)


Just in case what are the escape codes for commas and full stops, and question marks just in case my error pops up again?


Nevermind, looks like the issue I was having with a bad character was actually a CR LF pair which had somehow ended up in the middle of the body of text via a text editor.


Log in to post a reply.

Support

Forums