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
Simple if -problem
Sazureth Offline
Junior Member

Posts: 20
Threads: 8
Joined: Jan 2012
Reputation: 0
#1
Simple if -problem

Hi, I'm currently practising scripting for my first project and I'm having problems with constantly running a check.
What I want to do is make something happen when player health drops below, let's say 50, but I don't know how to do that.
Where do I have to put the if-structure if I want the check to be ran every update (constantly, so when the health drops stuff happens) without other conditions?

Right now it looks like this. Amnesia gives error complaining about the if.
if (GetPlayerHealth() < 50.0f)
{
    FadeEnemyToSmoke("servant_grunt", true);
}
(This post was last modified: 01-02-2012, 03:56 AM by Sazureth.)
01-02-2012, 01:28 AM
Find
Linus Ågren Offline
Senior Member

Posts: 309
Threads: 58
Joined: Jan 2011
Reputation: 5
#2
RE: Simple if -problem

Show us the entire script. The code works fine for me.

Creator of The Dark Treasure.
01-02-2012, 01:40 AM
Website Find
Sazureth Offline
Junior Member

Posts: 20
Threads: 8
Joined: Jan 2012
Reputation: 0
#3
RE: Simple if -problem

void OnStart ()
{
    SetPlayerHealth(20.0f);
    GiveItemFromFile("tinderbox_", "tinderbox.ent");
    GiveItemFromFile("lantern", "lantern.ent");
    GiveItemFromFile("potion_oil_", "potion_oil.ent");
    SetPlayerLampOil(80.0f);
    //void AddPlayerLampOil(float afOil);
    //float GetPlayerLampOil();
    AddEntityCollideCallback("Player", "test1", "GiveHealth", true, 1);
}

void GiveHealth(string &in asParent, string &in asChild, int alState)
{
    if(alState == 1)
    {
        SetPlayerHealth(100.0f);
    }
}

//everything above is random testing

if (GetPlayerHealth() < 80.0f)
{
    FadeEnemyToSmoke("servant_grunt", true);
}
01-02-2012, 02:14 AM
Find
Linus Ågren Offline
Senior Member

Posts: 309
Threads: 58
Joined: Jan 2011
Reputation: 5
#4
RE: Simple if -problem

You need to put the if-statement inside a function, or else it won't work.

Creator of The Dark Treasure.
01-02-2012, 02:19 AM
Website Find
Sazureth Offline
Junior Member

Posts: 20
Threads: 8
Joined: Jan 2012
Reputation: 0
#5
RE: Simple if -problem

I though so. Then, how can I create a function without conditions? ^^'''
01-02-2012, 02:22 AM
Find
Linus Ågren Offline
Senior Member

Posts: 309
Threads: 58
Joined: Jan 2011
Reputation: 5
#6
RE: Simple if -problem

Well, it's too bad you can't really make it work without having conditions.

I would had tried two different approaches to this:

Option 1:
If you have a collide box where you scripted that a mob shall spawn, add a timer in it.

Code that timer to use your script and outside of your if-statement, make a timer with the same name as the one you're currently in (so that it repeats [OR make a for/while-loop, but I don't loop it that way in Amnesia ^^]).

The script should be executed when the player has less than 50 health less, so inside the if-statement, put a RemoveTimer script BELOW the FadeEnemyToSmoke script.

Option 2:
Make a collide script with the actual monster, so when the player collides with the monster with less than 50 health, he shall fade away.

Creator of The Dark Treasure.
(This post was last modified: 01-02-2012, 02:27 AM by Linus Ågren.)
01-02-2012, 02:27 AM
Website Find
Sazureth Offline
Junior Member

Posts: 20
Threads: 8
Joined: Jan 2012
Reputation: 0
#7
RE: Simple if -problem

Okay, that helps alot! Thanks!

I'm too used to just being able to throw the if-thingy in the main loop.


/E: .....on the other hand, could you give a simple example? So far I haven't succeeded..
/E2: Okay, solved. My friend just accidently the whole script. I had wrong name for an object because of him.
(This post was last modified: 01-02-2012, 03:43 AM by Sazureth.)
01-02-2012, 02:33 AM
Find




Users browsing this thread: 3 Guest(s)