Eos IF Statements
- bakak17
- Explorer
- Posts: 8
- Joined: Thu Mar 26, 2020 5:44 pm
- Gender: Male
- Sexual Orientation: Bisexual/Bi-Curious
- I am a: Switch
- Location: Netherlands
Eos IF Statements
So I made a variable called "cbt" which is set to 0 at the beginning of the tease, and the user is asked if they like cbt. If they answer yes, the variable is changed to be 1. Now, when I get to this
action while previewing the tease, it always displays the actions for if cbt=1 even when cbt=0! How do I fix this?-bakak17
-
- Explorer
- Posts: 96
- Joined: Sat Aug 24, 2019 11:42 am
- Gender: Male
- Location: Germany
Re: Eos IF Statements
That is because a single equal-sign is an assignment. You are telling EOS to make cbt equal to 1 inside the if. The result of the assignment then is also 1, which gets converted to true.
To fix it, make it two equal signs: cbt==1
That is a comparison which can result in either true or false.
I have explained a similar case in my tutorial in part IV chapter 2, if you want to take a look.
To fix it, make it two equal signs: cbt==1
That is a comparison which can result in either true or false.
I have explained a similar case in my tutorial in part IV chapter 2, if you want to take a look.
- bakak17
- Explorer
- Posts: 8
- Joined: Thu Mar 26, 2020 5:44 pm
- Gender: Male
- Sexual Orientation: Bisexual/Bi-Curious
- I am a: Switch
- Location: Netherlands
-
- Explorer At Heart
- Posts: 552
- Joined: Sun Jul 06, 2014 2:11 pm
- Gender: Male
- Sexual Orientation: Open to new ideas!
- I am a: Slave
Re: Eos IF Statements
I would however set cbt to true and false.
And then use cbt directly as a predicate, no need for the == 1.
And then use cbt directly as a predicate, no need for the == 1.
Re: Eos IF Statements
While not exactly an an answer to the original question, just clarify all this if stuff:
Is equivalent to:
Is also equivalent to:
All the above are 'truthy' evaluations using Abstract Equality via implicit evaluation or double equals.
For example:
Javascript also has Strict Equality comparisons using triple equals:
But, back to double equals:
Generally, you should try to use strict comparisons with triple equals, else you could end up getting a true result when you were after false.
(There's also the inverse of == (abstract equals), != (abstract not equals), and the inverse of === (strict equals), !== (strict not equals))
Code: Select all
var x = 1
(x == 1) // evaluates as true
Code: Select all
var x = 1
(x) // evaluates as truthy
Code: Select all
var x = 1
(x == true) // evaluates as true
For example:
Code: Select all
('66' == 66) // evaluates as true.
Code: Select all
(66 === 66) // evaluates as true
('66' === 66) // evaluates as false
(true === true) // evaluates true
(1 === true) // evaluates false
Code: Select all
(1 == true) // evaluates true
(There's also the inverse of == (abstract equals), != (abstract not equals), and the inverse of === (strict equals), !== (strict not equals))
Last edited by fapnip on Thu Apr 23, 2020 3:54 pm, edited 2 times in total.
-
- Explorer
- Posts: 96
- Joined: Sat Aug 24, 2019 11:42 am
- Gender: Male
- Location: Germany
Re: Eos IF Statements
I think you mean 'truthy', but whatever: Honestly, the both of you are just scaring away beginners with this perfectionism and I would rather have them tell their stories with unoptimized/questionable code than not at all.fapnip wrote: ↑Thu Apr 23, 2020 3:13 pmAll the above are 'Falsy' evaluations[/code]Code: Select all
var x = 1 (x == true) // evaluates as true
"No master has yet fallen from the sky!"...
Re: Eos IF Statements
I'm a firm believer that information doesn't scare away beginners, but instead gives them the tools to figure out why something isn't working when they eventually hit a wall.
JavaScript's abstract evaluations, while useful in many cases, are at the core of countless bugs. I'm not sure how knowing what they are is scary, or "perfectionism", but my sincere apologies to anyone experiencing nightmares while in pursuit of perfect variable equality!
(Yes, meant truthy.)
JavaScript's abstract evaluations, while useful in many cases, are at the core of countless bugs. I'm not sure how knowing what they are is scary, or "perfectionism", but my sincere apologies to anyone experiencing nightmares while in pursuit of perfect variable equality!
(Yes, meant truthy.)
Who is online
Users browsing this forum: No registered users and 21 guests