Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Checks whether you got an item
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#3
RE: Checks whether you got an item

Take a gander at the signature for the HasItem function:
bool HasItem(string& asName);

You may notice it returns a boolean value; That is to say a "True" or "False". If statements work by evaluating the expression between the brackets to either a "True" or "False", and executing the following code if the statement evaluated to true.

What you are doing, is you are running the HasItem function, but aren't doing anything with the result. Instead you are checking If "alState" is 0 - This variable does not hold the result of any function, it is often used as a parameter in callback functions though.

A final point is you want to determine IF the player doesn't have the item. Not if they DO have it. There are two ways you could approach this:
1) HasItem() == false
2) !HasItem()
The first may initially seem easier to read -"if the player having the item is false". However, the "!" just means "not" - and it turns True into False and vice versa. It is actually just as legible and actually a better way to write the function.
if (!HasItem("stone_hammer_1"))
{
GiveItemFromFile("stone_hammer_1", "stone_hammer.ent");
return;
}
As the if statement will try to evaluate the function "HasItem" - this in turn will return true or false and execute the following code. "alState" is not a place where functions store their result.
(This post was last modified: 10-25-2011, 11:39 AM by Apjjm.)
10-25-2011, 11:33 AM
Find


Messages In This Thread
Checks whether you got an item - by flamez3 - 10-25-2011, 08:45 AM
RE: Checks whether you got an item - by jens - 10-25-2011, 11:31 AM
RE: Checks whether you got an item - by Apjjm - 10-25-2011, 11:33 AM
RE: Checks whether you got an item - by flamez3 - 10-25-2011, 12:29 PM



Users browsing this thread: 1 Guest(s)