# Ultimate Noob Coding

**URL:** <https://forum.choiceofgames.com/t/ultimate-noob-coding/28655>\
**Category:** ChoiceScript Help\
**Created:** [July 12, 2017, 10:33am UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655 "2017-07-12T10:33:30Z")\
**Posts on this page:** 20\
**Page:** 40

<div class="post-metadata">

**Author:** ![Cecilia\_Rosewood](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cecilia_rosewood/32/253835_2.png) [@Cecilia\_Rosewood](https://forum.choiceofgames.com/u/Cecilia_Rosewood)\
**Post date:** [June 30, 2024, 2:52am UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/796 "2024-06-30T02:52:56Z")

</div>

> [@Stormtrippin](#):
>
> \*The Intelligence scores are overlapping and one of the paragraphs will never be reached.

Imagine your game like a road. If, elseif, and else statements are where this road branches off.

The player is in a car, following the directions on the road signs.

At each sign they will check if their stats mean they need to turn off the main road there.

They will take a turn off the first side road they reach that their stats allow for.

Once they take a turn, branches further down the original road will not be reached unless jumped to using a goto command.

(Will draw some example diagrams when it’s not 4 am)

Edit with the promised diagrams:

> **This is how your current code would work if everything was correctly indented**
>
> ![Current code int 50](https://global.discourse-cdn.com/choiceofgames/original/3X/6/6/66847fa6d9138bea2d26c01a42efc8c0a6ed47a4.png)
> 
> ![Current code int 35](https://global.discourse-cdn.com/choiceofgames/original/3X/9/1/91d4d2eeb0f706792f44cf2d1934c4e55faa2a6b.png)
> 
> ![Current code int 20](https://global.discourse-cdn.com/choiceofgames/original/3X/7/d/7df3eaa7f597d547ffba13f59b5812ead1e674e1.png)

> **This is how you intended it to work**
>
> ![Correct code int 50](https://global.discourse-cdn.com/choiceofgames/original/3X/d/b/db654ed8103d2355e2efe3346fab003345cd05dd.png)
> 
> ![Correct code int 35](https://global.discourse-cdn.com/choiceofgames/original/3X/6/4/64ee57b577d3bb59610b4d209d690118ca5209a3.png)
> 
> ![Correct code int 20](https://global.discourse-cdn.com/choiceofgames/original/3X/5/d/5dc3fc9931c8af20db3f5092b34afc084367e385.png)

---

<div class="post-metadata">

**Author:** ![LiliArch](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/liliarch/32/120749_2.png) [@LiliArch](https://forum.choiceofgames.com/u/LiliArch)\
**Post date:** [June 30, 2024, 2:59am UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/797 "2024-06-30T02:59:24Z")

</div>

> [@Stormtrippin](#):
>
> \*An “else” is at the same indentation level as one of the “gotos” meaning it will never trigger. The solution for this is to indent the gotos further…?

No, the solution is to indent the else (and potential accompanying elseifs) on the same level where the if is.

---

<div class="post-metadata">

**Author:** ![Stormtrippin](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/stormtrippin/32/250944_2.png) [@Stormtrippin](https://forum.choiceofgames.com/u/Stormtrippin)\
**Post date:** [July 4, 2024, 5:55pm UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/798 "2024-07-04T17:55:36Z")

</div>

Hey, back at it again with another issue involving ifs and elseifs. This time I’m…fairly certain that it shouldn’t be an indentation issue because I’ve been using tabs instead of spaces. I’m still getting an error about falling out of the choice, though. Is it just the values I’m using and I’m too bricked to understand basic math?

````choicescript
        *if (Discipline >= 40)
            Text description.
            *goto_scene wild7
       
        *elseif (Discipline < 40) and (Discipline >= 20)
            Text description.
            *goto_scene wild7
        
        *elseif (Discipline < 20)
            Text Description.
            *set PCohesion %-10
            *goto_scene wild7```
````

---

<div class="post-metadata">

**Author:** ![Cecilia\_Rosewood](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cecilia_rosewood/32/253835_2.png) [@Cecilia\_Rosewood](https://forum.choiceofgames.com/u/Cecilia_Rosewood)\
**Post date:** [July 4, 2024, 5:59pm UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/799 "2024-07-04T17:59:16Z")

</div>

If you’re using elseif, the last command in the list always has to be an else. It’s kind of an “if none of the things above apply, then do this” statement. ChoiceScript gets confused and will throw up errors if it can’t find it.

In this case, replace the

> \*elseif (Discipline \< 20)

with

> \*else

and you should be good.

---

<div class="post-metadata">

**Author:** ![Lan](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/lan/32/80851_2.png) [@Lan](https://forum.choiceofgames.com/u/Lan)\
**Post date:** [July 4, 2024, 10:13pm UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/800 "2024-07-04T22:13:26Z")

</div>

Can you post the whole code for the choice this segment appears in?

> **The code you posted works fine for me.**
>
> Only modification was removing 2 levels of indents from each line.
> 
> ![image](https://global.discourse-cdn.com/choiceofgames/original/3X/0/7/079c3bc876e18194558d9779be00e7222e74a005.png)

I suspect your error is happening in the broader choice, or maybe in `wild7.txt`.

* * *

> [@Cecilia\_Rosewood](#):
>
> If you’re using elseif, the last command in the list always has to be an else.

Is that something ChoiceScript used to require in the past?

Because I use `*if`/`*elseif` without a final `*else` all the time. I typically don’t need–or want–a catchall.

> **For a really slapdash example:**
>
> This compiles and passes both QT and RT.
> 
> ```choicescript
> *create strength 50
> *create charisma 50
> *create dragon_regard 1
> *rand strength 15 85
> *rand charisma 15 85
> 
> (Strength is ${strength}, Charisma is ${charisma}.)
> 
> You meet a dragon.
> 
> *if strength > 65
> "I have heard impressive tales of your strength," the dragon says. "I admire that greatly."
> *set dragon_regard + 3
> *goto gold_pile
> *elseif charisma > 75
> "People speak highly of your oratory skill," the dragon says. "I'm something of an orator myself."
> *set dragon_regard + 2
> *goto gold_pile
> *elseif (strength > 60) and (charisma > 60)
> "People say you are quite a skilled individual," the dragon says.
> *set dragon_regard + 1
> *goto gold_pile
> 
> *label gold_pile
> 
> The dragon regards you cautiously, basking languidly atop a pile of gold coins.
> *ending
> 
> ```

* * *

In my opinion:

1. `*if/*if/*if...` is for outcomes that aren’t mutually exclusive or mandatory. You want to show multiple extra bits to some players.

2. `*if/*elseif(s)` is for outcomes that are mutually exclusive but not mandatory. You want to show exactly one of multiple possible extra bits to some players.

3. `*if/*elseif(s) [optional]/*else` is for outcomes that are mutually exclusive and mandatory. Everyone needs to get exactly one bit.

---

<div class="post-metadata">

**Author:** ![Havenstone](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/havenstone/32/198451_2.png) [@Havenstone](https://forum.choiceofgames.com/u/Havenstone)\
**Post date:** [July 4, 2024, 11:28pm UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/801 "2024-07-04T23:28:12Z")

</div>

Fantastic summary, thanks. I always learn from these threads. 🙂

Would you mind if I worked your summary into the [relevant bit of the Wiki](https://choicescriptdev.fandom.com/wiki/If#*if_used_in_combination_with_*elseif_and_*else)?

---

<div class="post-metadata">

**Author:** ![Lan](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/lan/32/80851_2.png) [@Lan](https://forum.choiceofgames.com/u/Lan)\
**Post date:** [July 4, 2024, 11:45pm UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/802 "2024-07-04T23:45:00Z")

</div>

Sure, I wouldn’t mind at all. Glad it was useful; when I start rambling I’m never sure.

---

<div class="post-metadata">

**Author:** ![Havenstone](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/havenstone/32/198451_2.png) [@Havenstone](https://forum.choiceofgames.com/u/Havenstone)\
**Post date:** [July 5, 2024, 1:19am UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/803 "2024-07-05T01:19:41Z")

</div>

Excellent, I’ve updated the \*if and \*elseif pages using your work.

---

<div class="post-metadata">

**Author:** ![Cecilia\_Rosewood](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cecilia_rosewood/32/253835_2.png) [@Cecilia\_Rosewood](https://forum.choiceofgames.com/u/Cecilia_Rosewood)\
**Post date:** [July 5, 2024, 3:36am UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/804 "2024-07-05T03:36:16Z")

</div>

> [@Lan](#):
>
> Because I use `*if`/`*elseif` without a final `*else` all the time. I typically don’t need–or want–a catchall.

It’s never worked for me, but then again I rarely ever use elseif. The else thing is just how I remember learning how to use elseifs.

I use ifs without an else (or gotos) all the time and that’s never been a problem.

---

<div class="post-metadata">

**Author:** ![Havenstone](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/havenstone/32/198451_2.png) [@Havenstone](https://forum.choiceofgames.com/u/Havenstone)\
**Post date:** [July 5, 2024, 4:36pm UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/805 "2024-07-05T16:36:17Z")

</div>

Whatever coding method works for you is the one you should use. ChoiceScript is for everyone. That’s the first and last thing I’d say about any of this stuff.

There are advantage to getting comfortable with elseifs. Pull out the if/elseifs from Lan’s example:

```choicescript
*if strength > 65
*elseif charisma > 75
*elseif (strength > 60) and (charisma > 60)

```

If you want to achieve the same results using \*ifs alone, I beileve you’d need:

```choicescript
*if (strength > 65)
*if (strength <= 65) and (charisma > 75)
*if ((strength > 60) and (charisma > 60)) and ((strength <= 65) and (charisma <= 75))

```

That’s a lot more fiddly code-typing and at least double the opportunity for typos.

But that doesn’t mean elseifs are necessary. Some people will no doubt find it easier to keep track of the conditions when they’re all written out like that (rather than implicit in the \*elseifs), especially if there are long stretches of text and other code in between the conditional commands. Some people hate `*goto`s so much that they’d count the extra typing a small price to avoid those three extra `*goto next`s. And of course, you can write a perfectly good game that never gives the reader a list of “mutually exclusive but not mandatory” options.

Whatever coding method works for you is the one you should use. ChoiceScript is for everyone.

---

<div class="post-metadata">

**Author:** ![Stormtrippin](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/stormtrippin/32/250944_2.png) [@Stormtrippin](https://forum.choiceofgames.com/u/Stormtrippin)\
**Post date:** [July 6, 2024, 7:08pm UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/806 "2024-07-06T19:08:00Z")

</div>

I just used an \*else instead of an \*elseif and it still threw an error.

````choicescript
  #You take aim at the officer and pull the trigger.
      *if (Discipline >=30)
          You got him.
          *goto_scene wild7
      
      *elseif (Discipline < 30)
          You missed.
          *goto_scene wild7
      
  #You take aim at the machine gunner and pull the trigger.
      *if (Discipline >= 40)
          You got him but better.
          *goto_scene wild7
       
      *elseif (Discipline < 40) and (Discipline >= 20)
          You got him.          
          *goto_scene wild7
        
      *else
          You missed.
          *set PCohesion %-10
          *goto_scene wild7
        
    #You take aim at one of the riflemen and shoot.
        Rollin' rollin' rollin' rollin
       *goto_scene wild7

    #You shoot over the enemy’s head. You don’t want to kill anyone.
        You escape this time.
       *goto_scene wild7```
````

---

<div class="post-metadata">

**Author:** ![Havenstone](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/havenstone/32/198451_2.png) [@Havenstone](https://forum.choiceofgames.com/u/Havenstone)\
**Post date:** [July 6, 2024, 7:14pm UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/807 "2024-07-06T19:14:09Z")

</div>

You need all the #Options to be at the same indent level.

And here:

\*if (Discipline \>=30)  
\*elseif (Discipline \< 30)

You can just use \*else instead of `*elseif (Discipline < 30)`, because that covers all the logical possibilities.

If you do use an \*if/\*elseif after an #Option, you’ve got to make sure there’s somewhere for the code to go – either an \*else or a \*goto indented at the same level as the \*if/\*elseif. Right now you don’t have that.

---

<div class="post-metadata">

**Author:** ![Stormtrippin](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/stormtrippin/32/250944_2.png) [@Stormtrippin](https://forum.choiceofgames.com/u/Stormtrippin)\
**Post date:** [July 7, 2024, 12:23am UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/808 "2024-07-07T00:23:39Z")

</div>

Got it. Do \*if commands need to be part of a choice or can I use them to display certain text based on if a variable is true or not?

---

<div class="post-metadata">

**Author:** ![Havenstone](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/havenstone/32/198451_2.png) [@Havenstone](https://forum.choiceofgames.com/u/Havenstone)\
**Post date:** [July 7, 2024, 1:04am UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/809 "2024-07-07T01:04:09Z")

</div>

You can use \*if to display text without a \*goto. This will work:

```choicescript
You went to school, took the exam, 
*if (exam_passed) 
        passed it, 
and then went to lunch

```

If you use \*elseif or \*else with your \*if, though, each bit needs to end with a \*goto. You do it correctly in the “take aim at the machine gunner” segment.

For your “shoot the officer” bit, any of these three ways could work:

```choicescript
#You take aim at the officer and pull the trigger.
      *if (Discipline >=30)
          You got him.
          *goto_scene wild7
      *else
          You missed.
          *goto_scene wild7

```

```choicescript
#You take aim at the officer and pull the trigger.
      *if (Discipline >=30)
          You got him.
          *goto_scene wild7
      *elseif (Discipline < 30)
          You missed.
          *goto_scene wild7
      *goto_scene wild7

```

```choicescript
#You take aim at the officer and pull the trigger.
      *if (Discipline >=30)
          You got him.
      *if (Discipline < 30)
          You missed.
      *goto_scene wild7

```

The first way is simplest and least bug-prone.

---

<div class="post-metadata">

**Author:** ![Stormtrippin](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/stormtrippin/32/250944_2.png) [@Stormtrippin](https://forum.choiceofgames.com/u/Stormtrippin)\
**Post date:** [July 7, 2024, 3:54pm UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/810 "2024-07-07T15:54:47Z")

</div>

I should elaborate- this is for a different section. Your previous fix didn’t trip any more errors, this is just a hypothetical.

---

<div class="post-metadata">

**Author:** ![Havenstone](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/havenstone/32/198451_2.png) [@Havenstone](https://forum.choiceofgames.com/u/Havenstone)\
**Post date:** [July 7, 2024, 4:33pm UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/811 "2024-07-07T16:33:35Z")

</div>

Yep, just giving you illustrations of what the \*gotos need to be doing with the if/else, if/elseif, and if/if approaches when they’re part of an #Option block.

---

<div class="post-metadata">

**Author:** ![mayaya](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/mayaya/32/269056_2.png) [@mayaya](https://forum.choiceofgames.com/u/mayaya)\
**Post date:** [July 10, 2024, 11:55pm UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/812 "2024-07-10T23:55:07Z")

</div>

Quick minor question, how do I set one variable to equal another? Like if I wanted variable1 to be set to variable2, would I not use [\*set variable1 = variable2]? It turned up an error when I tried this. I also tried [\*set variable1 = “${variable2}”]

(I’m sure it’s been asked before but I couldn’t find the appropriate posts)

---

<div class="post-metadata">

**Author:** ![Havenstone](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/havenstone/32/198451_2.png) [@Havenstone](https://forum.choiceofgames.com/u/Havenstone)\
**Post date:** [July 11, 2024, 12:05am UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/813 "2024-07-11T00:05:19Z")

</div>

> [@mayaya](#):
>
> \*set variable1 = variable2

Do it without the = sign: `*set variable1 variable2`

---

<div class="post-metadata">

**Author:** ![mayaya](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/mayaya/32/269056_2.png) [@mayaya](https://forum.choiceofgames.com/u/mayaya)\
**Post date:** [July 11, 2024, 12:10am UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/814 "2024-07-11T00:10:06Z")

</div>

That fixed it, thank you!

---

<div class="post-metadata">

**Author:** ![Stormtrippin](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/stormtrippin/32/250944_2.png) [@Stormtrippin](https://forum.choiceofgames.com/u/Stormtrippin)\
**Post date:** [July 19, 2024, 4:11pm UTC](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655/815 "2024-07-19T16:11:30Z")

</div>

I’ve been having an issue on the stats screen where some of the text isn’t displayed in the bar. It is an opposed stat, and the text on the left side appears, but the text on the right does not.

````opposed_pair
        Rebelliousness
    opposed_pair Merciful
        Ruthless```

For context, it is specifically the "Merciful" variable that does not appear. Everything else does.
````

[Previous page](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655.md?page=39)

[Next page](https://forum.choiceofgames.com/t/ultimate-noob-coding/28655.md?page=41)
