View Single Post
  #5  
Old 06-26-2013, 04:11 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by callimuc View Post
1st: style your code and please use PHP tags
2nd: you should always do '==' checks and not '=' checks within if() statements and such

now that we fixed this, your code will look like the following which makes it easier for us to read:

PHP Code:
... 

personally I would do something like:

PHP Code:
... 

I would still do one main script in a class and then have the weapons linked to that class using this.join("classname"); so once you are doing a change, you dont need to update all weapons (depending on the change)

Just a small addition to what callimuc posted, you do not need to check if something equals to true or false, as the if statement will go through if the value given equals true or false itself.

For example
NPC Code:

if (keydown(4) == true)



is the same as doing
NPC Code:

if (1 == 1) // keydown(4) returns true since they key was held down



the keydown() function returns a value of true or false depending on if the button specified is held down or not, and since booleans in graal basically converts into 1(true) and 0(false), we can use that!

Also, doing if (1 == 1) is in theory slower than doing if (1)

The speed difference isn't really noticed though, but here I am, saying it anyways

Also another edition, the ! operator functions in the way that it inverses the bit. Basically 0 would become 1 and 0 would become 1.

This is the reason you can do if (!keydown(4)) and it would fall through since the inverse of 0(false) is 1(true).
__________________
Reply With Quote