[RESOLVED] Problem with *if and *elseif

Hello. So, I just started my game and when I was testing it some bug appeared and I’m failing to fix it ;-; could some good soul help me here?

The error is: “startup line 254: no expression specified”

In these lines are:

 #No, I refuse.
   You suspected you had depression, but you really hadn't any hopes that a doctor would help.
   *if truthful = true
        *goto Truth
   *elseif     
        *goto Lie

I’m really not understanding in what I went wrong ;-;

*choice
    #No, I refuse.
        You suspected you had depression, but you really hadn't any hopes that a doctor would help.
        *if {truthful = true}
            *goto Truth
        *elseif     
            *goto Lie

Try it like this?
I would suspect that you forgot the {}, at least it messes everything up whenever I forgot them

You can do it like this:

*choice
#No, I refuse.
…You suspected you had yadda yadda ya
…*if truthful
…*goto Truth
…*goto Lie

I put the {} and tested it again, but this time it said “variable.toLowerCase is not a function”
oh god ;-;

Oh, that worked! Thank you!

No worries. And my post must be 20 characters so here’s some more words.

You only use *elseif for you have several conditionals

So the puny human think they can hurt me eh?

*choice
#Do a basic attack
*goto attack
#Power Attack
*if (str<=3)
*goto gruesome_death_scene
*elseif ((str>4) and (str<=10))
Ha that tickles!!!
*goto round2
*elseif ((str>10) and (str<=20))
Ow! that hurt!!!
*goto round2_1
*else
Fatality!!!
set ogredead true
*goto final_scene

You* MUST* end a elseif chain with a final catch all *else

Is there a reason to use *elseif and *else?

Because this:

*choice
#Do a basic attack
…*goto attack
#Power attack
…*if (str<+3)
…*goto gruesome_death_scene
…*if ((str>4) and (str<=10))
…Ha that tickles!!!
…*goto round2
…*if ((str>10) and (str<=20))
…Ow! That hurt!!!
…*goto round2_1
…Fatality!!!
…*set ogredead true
…*goto final_scene

Works just as well.

1 Like

Plenty of reasons to use *elseif and *else it does not have to be used only in *choice statements but can be used for conditional text outputs like gender specific; used as a measuring device to put put players previous choices to a certain point in a story. It’s just a different way of going about doing things instead of using a lot of *if statements.

2 Likes

Ah okay then, I see.

1 Like

Read the section “Fake bugs in Quicktest” for the reason CoG will often make you use *else in your choices. The short version is, it keeps the game from crashing if you’ve overlooked something – for example,

*if strength > 50
  *goto strong
*if strength < 50
  *goto wimpy

runs into problems if strength = 50 (and plenty of people who come asking for coding help have overlooked something along these lines).

As you clearly know from your example, you could tweak the code to fix that one without using *else:

*if strength > 50
  *goto strong
*if strength <= 50
  *goto wimpy

But that wouldn’t (I think?) pass Quicktest, which would insist on:

*if strength > 50
  *goto strong
*else
  *goto wimpy

And CoG won’t accept a game that doesn’t pass Quicktest.

Edit: and note that in your example, using elseif allows you to drop a whole lot of conditions and parentheses:

*choice
  #Do a basic attack
    *goto attack
  #Power attack
    *if str<3
      *goto gruesome_death_scene
    *elseif str<=10
      Ha that tickles!!!!
      *goto round2
    *elseif str<=20
      Ow! That hurt!!!
      *goto round2_1
    *else
      Fatality!!!!!
      *set ogredead true
      *goto final_scene
1 Like

Oh. Well then, I’ll have to go back and change all that in my game then. Didn’t realise it was a prerequisite to getting a game published.

Actually, so far I’ve done things like this:

*if strength
…You’re so strong!

*if speed
…You’re so fast!

If you will, please train me to be like you.

That would pass quicktest right? Since it’s just a true/false if statement and there are no numbered stats.

Yeah, I didn’t properly get it either until the first time I ran Quicktest on my WiP. Much editing, much griping…

Yes, your example would pass Quicktest. Run QT on your game draft and see how often it chokes on your code (the “falling out of choice” error will be the one in question). That should give you a pretty good sense of what bits need an *else and which don’t.

2 Likes

Took me a little bit to figure out how to quicktest and randomtest. But I got it now. This stuff is going to be a lifesaver. Already got a “It is illegal to fall out of a *choice statement; you must *goto or *finish before the end of the indented block.”

Thanks for the help.

1 Like