*if command help


#1

Sorry to bother anyone, but I need some help…

So I’m not sure if I am doing something wrong or maybe I don’t fully understand how to use the *if command.
So in one scene I have it end in two different ways. Either *set sad true or *set mad true
In the next scene, I have something like this.

*if sad = true 
      Then sad stuff….
*if mad = true 
     Then mad stuff….

And more stuff

After the “mad scene” I want it to go to the text with the mad stuff then on to more stuff…but it always goes to the sad stuff and not mad…………sorry if that’s confusing… I know I can use *goto commands but in some cases I feel the set true or false thing will be better…

Also… I have something like this

*label something
*page_break 
Some text… 

but there is not page break the next text shows up with the text before….


#2

Go back and double check things.

*create sad false
*create mad false

Are you certain that only mad or sad is set true? Since they’re different variables it’s possible for both of them to be true at the same time, so you’ll need to go back, check your code, make sure that you’ve only got one.

You could do *create mood “blank” then *set mood “sad” or *set mood “mad” at least that way you’ll be certain it can only be one of those.


#3

I will look over it again but I am very sure that it can either only be sad or mad…


#4

but if I do right a thing that says *if something and then text after it, only that text will show if it is set true and then move on to the text under and never show text that is not true?


#5

I think I might just have to use *goto commands…which should work fine too. sometimes I just get confused on the best way to do things…


#6

Can I do something like:
*if mad = true goto scene mad

or does it have to be like
*if mad = true
*goto scene mad


#7

on and…if I want text to show up or a certain scene to show up ONLY if a stat was a certain level, what would the best way to do that be?
for example…
I have *set focus +1

*if focus > 1

and some text under it

then I go on to other stuff but can’t seem to make ONLY the “focus text” to show when the IF is in place…ugh =p


#8

You can use:

*create emotion “sad”
*create emotion “mad”
or
*create sad false
*create mad true

*if emotion = “sad”
*goto blah blah
*if emotion = “mad”
*goto blah blah blah
or
*if emotion = “sad”
*goto blah blah
*else
*goto mwhahahaha
or
*if (sad)
*goto blah blah
*if (mad)
*goto blah blah blah

And so on and on for whatever you feel like it. The if can use the *goto or not depending on what your trying to do.


#9

@honeymichie awesome! that’s totally what I was looking for… but hey…what are you doing responding to me…you should be working on your own book right now!! haha


#10

Taking a break from writing and wanted to lurk in the shadows because this frog is thinking of ideas. Lols.

Oh yeah forgot to add. You don’t really need to write the = false or = true command. You can replace them with.
*if (var) – this is true
*if not (var) – this is false

You don’t really need to add a *goto at the end of an *if command. That is if you won’t use the *elseif and *else command

*if (var)
I just realized you and fairy have bird avatars.

*if (var)
*goto blah_blah
*elseif not (var)
*goto mwah_blah

This is an equal to example:
*if focus = 1
You’re focused on blah

This is a not equal to example:
*if focus != 1
You’re not focused blah

This is a greater than example:
*if focus > 1
You’re definitely focus blah

This is a less than example:
*if focus < 1
You’re not focused blah

This is a greater than or equal to example:
*if focus >= 1
You’re definitely focus blah

This is a less than or equal to example:
*if focus <= 1
You’re not focused blah

Depends on what you’re looking for, hope this helps :grin:


#11

It’s generally preferred that you don’t make a zillion short posts one after each other. You can go back and edit previous posts, adding in your new questions, as opposed to making several posts in succession.

I use goto’s a lot because I find them simpler. You’ve to be careful with if statements since a wrong indentation and ifs mess up.

Your

*if sad = true
    Then sad stuff
*if mad = true
    Then mad stuff

should work though. If it’s not working, if you’re seeing sad then mad that’s because something’s wrong somewhere. It might be your indentations. If the indentation is like you’ve shown though, then yes the only way you’ll be seeing the if sad stuff is if sad is set true. So go back, check everywhere you set sad anything, check how you create it as well.

The best way to do things is however works best and easiest for you. I’ve seen games with absolutely no if statements, no variables, which just use gotos. There’s games that copy huge chunks of text, over and over again, with minor changes made, instead of using simple if statements.

Ifs were what I found trickiest when I coded my first game but with practice you’ll get used to them and they are a powerful tool.

But it’s really what works for you.

Go back and double-check your page_break. Make sure it is like that, and not the page_break first and then the label. The page_break should be showing.


#12

@honeymichie @FairyGodfeather ok thanks!!!


#13

Am i doing something wrong here? doesn’t seem to be adding any of the text when it checks the variables…

    As if able to read your mind all she does is flick you a smile 

    *if guards_unconcious
    	.Looking past you she notes the unconscious guards laying on the ground, making friends I see, she smirk
    *if (guards_dead = 3)
    	.Looking past you she notes the dead guards laying on the ground, not wanting to insight your wrath she steers at the ground
    *if (guards_dead = 2)
    	.Looking past you she notes the guard steering down at the body of his friend, not wanting to become the next, she steers at the ground

    while producing a bowl of grapes.

seems to be moving from
As if able to read your mind all she does is flick you a smile
while producing a bowl of grapes.


#14

@Dreamwalker Generally it’s better to start your own topic for something like this.

It looks like your indentations are fine from that sample.

What variables do you have set?
Do you mean to have unconscious spelled incorrectly?

Are those .'s things you added for the forum?


#15

@FairyGodfeather sorry, thought id look for *if topic before making a new one…

in the start up i have

 *create guards_dead 0

and in game “addings” to the variables

*if (kill_servant) 
		#End this fool
			*if (agility = 1)
				Although appearing calm, anger begins to consume you, unable to hold it back you dash forward while pulling out a hidden blade from the small of your back, before he had realised his fate you'd already opened his throat and sent the blade sailing through the air embedding itself deep within the others chest.
				Waking over to the second body you reach down and retrieve your blade.
				Cleaning it off you place it back within its sheath and walk on in to the tent
				*set intimidation + 1
				*set enter true
				*set guards_dead + 3
				*set psyche + 1
				*goto inside_tent

i do apologise if the content is not to anyones/everyones taste, and hope they can look pass that to the problem at hand, the coding…


#16

What I generally do, if some of my code isn’t working, is I take snippets of code and plug it into the online tester.

Link: https://dl.dropboxusercontent.com/u/7840892/CJW/choicescript/tools/IDE/main.html
Forum Thread [Tool] ChoiceScript Development Environment

Then I plug in values at the top to check and see if it’s working. So in your case I’d copy and paste in that section of code, then stick a

*create guards_unconscious false
*create guards_dead 0
*set guards_dead +3

at the top.

Then I’ll fiddle around until it works. If it does already work then I’ll assume the error’s in another bit of code and go hunting.

Is there a possibility your dead guard variable is being missed? Or that you’re ending up with 1 dead guard, or 4+ dead guards, since either way it’ll cause you to skip that section. Also, if your agility is above or below 1 then you’re not hitting that dead_guards increase either.


#17

Thank you for you assistance :slight_smile:


#18

After every *if you need to end that part with a *fish or *goto
This is how I do mine.

 *if smart
          You are very smart!
          *goto next
    
 *label next

#19

Normally I would agree, which is what I’ve done with choices, but it doesn’t appear in this case that that’s needed. been using it quite abit mid sentence to add character abilities to sections of the story. The problem I had was so silly I wanted to slap myself, it appeared I counted the stats wrong =4 so it wasn’t picking the check up…


#20

Just to clarify this for anyone else still learning: strictly speaking, you only need to use such as a *finish or *goto in those cases where your *if uses an *else. A series of *if statements like this -

*if var1 = 1
    *set var2 "Fred"
*if var1 = 2
    *set var2 "Bill"
*if var1 = 3
    *set var2 "Rita"
*if var1 = 4
    *set var2 "Josie"

do not strictly require a *finish or *goto for each case. The example above will work fine. However, in situations like this it is well worth taking a closer look at the useful *bug command, as it may actually be helpful to use a *goto even if not strictly needed: