Forum

> > CS2D > Scripts > 2 is equal to 1?
Forums overviewCS2D overview Scripts overviewLog in to reply

English 2 is equal to 1?

4 replies
To the start Previous 1 Next To the start

old 2 is equal to 1?

Mami Tomoe
User Off Offline

Quote
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:
1
if (i_type < 66 or i_type > 68) and trigger == house_id then

For a second there I started doubting math.

old Re: 2 is equal to 1?

VADemon
User Off Offline

Quote
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

old Re: 2 is equal to 1?

ohaz
User Off Offline

Quote
user Mami Tomoe has written
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:
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

old Re: 2 is equal to 1?

Mami Tomoe
User Off Offline

Quote
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.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview