Facebook Twitter YouTube Frictional Games | Forum | Newsletter | Dev Blog | Dev Wiki | Support | Shelf | Store

Privacy Policy


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scripting with if-clauses
Author Message
lemonpotatoe Offline
Junior Member

Posts: 6
Joined: Jul 2011
Reputation: 0
Post: #1
Scripting with if-clauses
Hey everyone,

I'm completely new to scripting, which makes me a total noob.

However, currently I'm stuck on a idea and I hope you can help me out.

Here's what I wanna do:

The player enters a room in which he can find the lantern. Once he has picked up the lantern and comes near the door, he walks into a script area which makes the door slam closed.

The lantern item is called "lantern", the area is called "lanternarea", the door is called "lanternarea_door".

Here's what I worked out so far:

void OnEnter()
{
AddEntityCollideCallback("Player", "lanternarea", "func_lanternarea", true, 1);
}

void func_lanternarea(string &in asParent, string &in asChild, int alState)
{
if(HasItem("lantern")==true)
{
SetSwingDoorClosed("lanternarea_door", true, true);
PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);
PlaySoundAtEntity("", "react_scare", "Player", 0, false);
PlaySoundAtEntity("", "close_door.snt", "Player", 0, false);
GiveSanityDamage(5.0f, true);
}
}
The map starts without any error messages, but when I walk into the area nothing happens.
Where exactly did I go wrong?

I hope someone can help me out. Smile

Cheers
07-18-2011 02:50 AM
Find all posts by this user Quote this message in a reply
Tanshaydar Offline
From Beyond

Posts: 3,091
Joined: Mar 2009
Reputation: 66
Post: #2
RE: Scripting with if-clauses
if statement checks something if it's true or not. So you don't need to check twice if it's true or not with HasItem("lantern")==true

if(HasItem("lantern")) is enough. Again, you can try with deleting if line and see if the code actually works and nothing works with it, then try with if and pick up the lantern to see if it works.

07-18-2011 03:01 AM
Visit this user's website Find all posts by this user Quote this message in a reply
lemonpotatoe Offline
Junior Member

Posts: 6
Joined: Jul 2011
Reputation: 0
Post: #3
RE: Scripting with if-clauses
Thanks for your reply.

I removed the if-line and it worked perfectly. But once I added the if line it again didn't work.

Maybe I entered the name "lantern" in the wrong fields? I've entered it in General > Name, Entity > CallbackFunc and Entity > PlayerInteractCallback.
07-18-2011 03:29 AM
Find all posts by this user Quote this message in a reply
Tanshaydar Offline
From Beyond

Posts: 3,091
Joined: Mar 2009
Reputation: 66
Post: #4
RE: Scripting with if-clauses
It should be entity's name.

07-18-2011 04:20 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ThePaSch Offline
Member

Posts: 103
Joined: Sep 2010
Reputation: 0
Post: #5
RE: Scripting with if-clauses
(07-18-2011 03:29 AM)lemonpotatoe Wrote:  Maybe I entered the name "lantern" in the wrong fields? I've entered it in General > Name, Entity > CallbackFunc and Entity > PlayerInteractCallback.

You don't put the entity's name into CallbackFunc and PlayerInteractCallback. These fields are for what their name suggests they are, for callbacks. Just like the callback you set up when the player and the area collide.

For the record, you didn't include the quotation marks at General > Name, did you?

(This post was last modified: 07-18-2011 06:42 AM by ThePaSch.)
07-18-2011 06:41 AM
Find all posts by this user Quote this message in a reply
lemonpotatoe Offline
Junior Member

Posts: 6
Joined: Jul 2011
Reputation: 0
Post: #6
RE: Scripting with if-clauses
OK, I removed the name from the other fields, so it's just in General > Name. I did not include the quotation marks in the field.

However, it still doesn't work. Any ideas? Sad
07-18-2011 09:42 AM
Find all posts by this user Quote this message in a reply
Tanshaydar Offline
From Beyond

Posts: 3,091
Joined: Mar 2009
Reputation: 66
Post: #7
RE: Scripting with if-clauses
General->Name-> Lantern

if(HasItem("Lantern"))

07-18-2011 09:49 AM
Visit this user's website Find all posts by this user Quote this message in a reply
lemonpotatoe Offline
Junior Member

Posts: 6
Joined: Jul 2011
Reputation: 0
Post: #8
RE: Scripting with if-clauses
(07-18-2011 09:49 AM)Tanshaydar Wrote:  General->Name-> Lantern

if(HasItem("Lantern"))
That's what I did, but it doesn't work.
07-18-2011 09:58 AM
Find all posts by this user Quote this message in a reply
Tanshaydar Offline
From Beyond

Posts: 3,091
Joined: Mar 2009
Reputation: 66
Post: #9
RE: Scripting with if-clauses
When you picked up the lantern, you go into area and nothing happens?

07-18-2011 10:20 AM
Visit this user's website Find all posts by this user Quote this message in a reply
lemonpotatoe Offline
Junior Member

Posts: 6
Joined: Jul 2011
Reputation: 0
Post: #10
RE: Scripting with if-clauses
(07-18-2011 10:20 AM)Tanshaydar Wrote:  When you picked up the lantern, you go into area and nothing happens?

Exactly. But, as said before, once I remove the if-clause the script works perfectly, which tells me that there is either something wrong with the if clause or (more likely) with my item name. Huh
07-18-2011 10:24 AM
Find all posts by this user Quote this message in a reply
Post Reply 




User(s) browsing this thread: