English 2 is equal to 1?

4 replies
Goto Page
To the start Previous 1 Next To the start
16.06.19 03:23:46 pm
Up
Goo
User
Offline Off
Code:
1
2
3
4
5
6
7
8
if i_type < 66 or i_type > 68 and trigger == house_id then
     hc.event(trigger .. ' == ' .. house_id)
     hc.event('----------------------------')

     table.insert(p_items, i_type)
                    
     parse('removeitem ' .. id)
end


IMG:https://i.imgur.com/3fvYjoS.png



I'm feeling very dumb even though it looks perfectly correct to me.


Edit: Never mind! I just needed to place brackets around the or statement like this:
Code:
1
if (i_type < 66 or i_type > 68) and trigger == house_id then


For a second there I started doubting math.
19.06.19 02:54:20 am
Up
VADemon
User
Offline Off
Actually this happened to me once, "100 == 100" was returning false.

Apparently it's possible for the cs2d API to return number values that do not equal written in code 100 (like
building.progress() == 100
)
Though when you tried tostring() on them, they'd be processed in Lua in show 100 like nothing happened

Floating point numbers (Lua uses reduced precision doubles) are always evil
19.06.19 07:52:37 am
Up
ohaz
User
Online On
user Goo has written:
Code:
1
if i_type < 66 or i_type > 68 and trigger == house_id then
Take a look at operator precedence. Also, always put parentheses around your if statements if they contain multiple queries.

Your if statement evaluates to:
Code:
1
if i_type < 66 or (i_type > 68 and trigger == house_id) then
which means that all i_types < 66 automatically trigger your if
https://ohaz.engineer - Software Engineering
19.06.19 12:54:09 pm
Up
Goo
User
Offline Off
Yeah, notice the edit.
I realized that quite soon after posting this.

I just added that trigger check a couple minutes later after I created that if, thus I didn't consider how it will affect it.

Turns out I just forgot to place it at the start or place brackets.
19.06.19 06:03:46 pm
Up
Devil-Thanh
GAME BANNED
Offline Off
Have you guys ever tried 0.1 + 0.2 == 0.3 in any programming languages?.
To the start Previous 1 Next To the start