Ultimate Noob Coding

I’m getting an error while trying that piece of code: Invalid expression at char 23, expected OPERATOR, was: STRING [“Bowl of cereal”]

Am i missing something?

Which code did you try? Might help to post the code (or a screenshot) of where you think the invalid expression is turning up. (does it give you a line?)

BTW is your variable one word? (You can set variables to be more than one word, but I think the variable in the startup needs to be single.)
ie *set bowlofcereal “Bowl of cereal” would be ok.
but *set bowl of cereal “Bowl of cereal” would likely error.

1 Like

This is exactly the line i used: *if (Break1 “Bowl of cereal”) #Bowl of cereal

That means you have some kind of complete statement immediately prior to “Bowl of cereal” and you need to put in some kind of operator; need to see the code to advise on which.

Important rule for these kinds of errors: they show up when the computer gives up and determines there’s no way it can find an interpretation of the code. The actual problem may be far earlier; lots of things are valid but not what you want.

Try *if (Break1 = “Bowl of cereal”) # choice

*btw pls ignore my stupid spelling above, it’s after midnight here and I just realised what I wrote.

1 Like

No, for some reason when i try that the breakfast item still appears but the code runs

Also @James_Marsh i could send you the code if you’d like although you will not like what you see, it’s computer generated so theres gonna be high numbered bubbles.

When you have an *if the thing in the parentheses needs to become a single true or false value. Here you have a variable and a fixed string, so you need a comparison operator in between to compute true or false. “=” is the one you want here.

Edit: that was assuming you wanted the option if Break1 is “Bowl of cereal”. See Jacic for if you want it if Break1 is not “Bowl of cereal”

1 Like

This will allow the choice to be selected if you have chosen cereal for break1. If you don’t want it to be able to be rechosen put

*if (Break1 != “Bowl of cereal”) # choice

This means it can only be chosen if break1 does not = bowl of cereal

By the way, watch making variables with capital letters. It can come back to bite you later as break1 is different to Break1 and won’t be recognised if you use the wrong one.

2 Likes

YES that works thank you!

Hey @James_Marsh You still want the code from that scene? :joy: I can still send you it so you can see how chronicler works @Jacic You too.

1 Like

That was the part of the code I’d needed in this case. I have enough code to read in my day job so I don’t need more for my own entertainment.

1 Like

I have another question, but this one’s optional for implementation for me. If you got the reader to type something how would you prevent the reader from typing the exact same thing for the next option? you don’t know what they’d type so how would you prevent it?

Edit 1: for example if the reader typed “Plate of Dicks” for their first breakfast item how would you prevent them from typing it again?

Edit 2: also sorry, someone mentioned plate of dicks yesterday and it got stuck on my mind XD

I would recommend you just let them and if it doesn’t make sense that’s the reader’s problem, but what you’d do is save the inputs, then after the second one check if they’re equal and if they are display “you can’t pick the same item twice” or some equivalent and then use *goto to send them back to the text box.

Also I would recommend against using text input for anything except just displaying the input in appropriate locations; it is exceedingly difficult to ensure you can correctly interpret anything the reader types in, especially if they use different spacing or hyphens from what you’re expecting.

1 Like

Yeah… that has a completely different meaning here :laughing: (Guessing you’re from the UK?)

If it doesn’t affect the story, agree with @James_Marsh and just let them go for it.

If you really don’t want them to, I think you can do something like

*if (break1 = break2)
  You can't eat the same thing twice! Choose something else.
  *goto chooseagain

(If that doesn’t work may need to check with someone else, but I think that’s the code for it.)

1 Like

@James_Marsh @Jacic Thank you two for all your help! You’re awesome!

2 Likes

That’s the code for a straight equality test, yes. If the strings are precisely identical it will function. If there’s any variation, even if the meaning is identical, it won’t. Capitalization might be an exception, couldn’t find out on the wiki, but it’s safer to assume “a” = “A” is false unless you know otherwise.

Hence my recommendation against relying on text inputs for anything except redisplaying them.

3 Likes

Yep you’re right, if you had break1 = “toast” and break2 = “Toast” it would think they’re different.
If you really want to, you can set a testing variable for each one to all capitals to avoid that. Won’t help if there’s any spacing, spelling or punctuation differences though.
@Classified if you’re going to be using a lot of free text entry that you want to check, probably worth reading the thread on riddles that had some info on that sort of thing. Will see if I can find it.

Here you go (not quite the same as what you’re doing but can be adapted. It’ll give you the gist of the idea):

1 Like

Okay I have a new question and this one involves math. I want a Variable like Morale display as the average of the relationship status of 4 people. For example, each person has 50% relationship, I want to multiply that number by 4 because there are 4 people and then divide it by four to show the average. How would I do that? And display it in the stats chart as morale.

I feel stupid :sob: i’m the only one asking questions here

@Jacic Help meeeee!

*set morale ((var1 + var2 + var3 + var4) /4)

I think

hmm. okay let me test that out.

Nope that doesn’t work

Do I have to physically set it or will it work as a variable?