Frictional Games Forum (read-only)

Full Version: Scripting with if-clauses
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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:

Code:
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
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.
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.
It should be entity's name.
(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?
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
General->Name-> Lantern

if(HasItem("Lantern"))
(07-18-2011, 09:49 AM)Tanshaydar Wrote: [ -> ]General->Name-> Lantern

if(HasItem("Lantern"))
That's what I did, but it doesn't work.

When you picked up the lantern, you go into area and nothing happens?
(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

Pages: 1 2