Frictional Games Forum (read-only)
Simple if -problem - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Simple if -problem (/thread-12263.html)



Simple if -problem - Sazureth - 01-02-2012

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.
Code:
if (GetPlayerHealth() < 50.0f)
{
    FadeEnemyToSmoke("servant_grunt", true);
}



RE: Simple if -problem - Linus Ågren - 01-02-2012

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


RE: Simple if -problem - Sazureth - 01-02-2012

Code:
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);
}



RE: Simple if -problem - Linus Ågren - 01-02-2012

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


RE: Simple if -problem - Sazureth - 01-02-2012

I though so. Then, how can I create a function without conditions? ^^'''



RE: Simple if -problem - Linus Ågren - 01-02-2012

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.


RE: Simple if -problem - Sazureth - 01-02-2012

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.