Eos IF Statements

Post all technical issues and questions here. We'll gladly help you wherever we can.
Post Reply
User avatar
bakak17
Explorer
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

Post by bakak17 »

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
Screen Shot 2020-04-21 at 2.42.53 PM.png
Screen Shot 2020-04-21 at 2.42.53 PM.png (103.65 KiB) Viewed 1429 times
action while previewing the tease, it always displays the actions for if cbt=1 even when cbt=0! How do I fix this?
-bakak17
undeniable_denial
Explorer
Explorer
Posts: 96
Joined: Sat Aug 24, 2019 11:42 am
Gender: Male
Location: Germany

Re: Eos IF Statements

Post by undeniable_denial »

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.
User avatar
bakak17
Explorer
Explorer
Posts: 8
Joined: Thu Mar 26, 2020 5:44 pm
Gender: Male
Sexual Orientation: Bisexual/Bi-Curious
I am a: Switch
Location: Netherlands

Re: Eos IF Statements

Post by bakak17 »

undeniable_denial wrote: Tue Apr 21, 2020 10:04 pm
To fix it, make it two equal signs: cbt==1
This worked, thank you!
-bakak17
kerkersklave
Explorer At Heart
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

Post by kerkersklave »

I would however set cbt to true and false.
And then use cbt directly as a predicate, no need for the == 1.
fapnip
Explorer At Heart
Explorer At Heart
Posts: 430
Joined: Mon Apr 06, 2020 1:54 pm

Re: Eos IF Statements

Post by fapnip »

While not exactly an an answer to the original question, just clarify all this if stuff:

Code: Select all

var x = 1
(x == 1) // evaluates as true
Is equivalent to:

Code: Select all

var x = 1
(x)  // evaluates as truthy
Is also equivalent to:

Code: Select all

var x = 1
(x == true)  // evaluates as true
All the above are 'truthy' evaluations using Abstract Equality via implicit evaluation or double equals.

For example:

Code: Select all

('66' == 66) // evaluates as true.
Javascript also has Strict Equality comparisons using triple equals:

Code: Select all

(66 === 66) // evaluates as true
('66' === 66) // evaluates as false
(true === true) // evaluates true
(1 === true) // evaluates false
But, back to double equals:

Code: Select all

(1 == true) // evaluates true
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))
Last edited by fapnip on Thu Apr 23, 2020 3:54 pm, edited 2 times in total.
undeniable_denial
Explorer
Explorer
Posts: 96
Joined: Sat Aug 24, 2019 11:42 am
Gender: Male
Location: Germany

Re: Eos IF Statements

Post by undeniable_denial »

fapnip wrote: Thu Apr 23, 2020 3:13 pm

Code: Select all

var x = 1
(x == true)  // evaluates as true
All the above are 'Falsy' evaluations[/code]
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.
"No master has yet fallen from the sky!"...
fapnip
Explorer At Heart
Explorer At Heart
Posts: 430
Joined: Mon Apr 06, 2020 1:54 pm

Re: Eos IF Statements

Post by fapnip »

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.)
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests