Frictional Games Forum (read-only)

Full Version: Using Global.hps to use a script in every level
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi all,

I'm looking to make a script run in every level. The script is to change an item in your inventory based on your sanity. I've tried a couple of methods but none seem to work. Here's my code as it stands:

global.hps
Code:
void OnGameStart()
{
    StartLocketLoop();
}

void StartLocketLoop();
{
    AddDebugMessage("Locket Looping", false);
    if(GetPlayerSanity() >= 70 && !HasItem("HighSanityLocket"))
    {
        RemoveItem("MidSanityLocket");
        RemoveItem("LowSanityLocket");
        GiveItem("HighLocket", "Locket", "HighLocket", "locket.tga", 1);
        AddDebugMessage("Give High Locket", false);
    }
    else if(GetPlayerSanity() < 70 && GetPlayerSanity() >= 30 && !HasItem("MidSanityLocket"))
    {
        RemoveItem("HighSanityLocket");
        RemoveItem("LowSanityLocket");
        GiveItem("MidLocket", "Locket", "MidLocket", "locket.tga", 1);
        AddDebugMessage("Give Mid Locket", false);
    }
    else if(GetPlayerSanity() < 30 && !HasItem("LowSanityLocket"))
    {
        RemoveItem("MidSanityLocket");
        RemoveItem("HighSanityLocket");
        GiveItem("LowLocket", "Locket", "MidLocket", "locket.tga", 1);
        AddDebugMessage("Give Low Locket", false);
    }
    ReloopLocketTimer();
}

void ReloopLocketTimer()
{
    AddTimer("LocketLoop", 1.0f, StartLocketLoop);
}

I've tried calling "StartLocketLoop" from a map file as well, but it still doesn't want to trigger. I've tried putting the same script into Inventory.hps, but to no avail. Also, does the global.hps keep running between loading maps and relaunching the game etc?

Thanks,
Cyfiawn
Code:
void OnGameStart()
{
    StartLocketLoop();
}

void StartLocketLoop() //There's an extra ;
That's one. I'll give you some lecturing here.

[if(GetPlayerSanity() >= 70 && !HasItem("HighSanityLocket"))]

Look at the code above. Do you see a bolded text? [!] in AngelScripting and C++ meant not. The code above is equivalent to...
[if(GetPlayerSanity() LARGER/EQUALS TO 70 AND NOT HasItem("HighSanityLocket"))]
(05-14-2013, 12:39 PM)JustAnotherPlayer Wrote: [ -> ]
Code:
void OnGameStart()
{
    StartLocketLoop();
}

void StartLocketLoop() //There's an extra ;
That's one. I'll give you some lecturing here.

[if(GetPlayerSanity() >= 70 && !HasItem("HighSanityLocket"))]

Look at the code above. Do you see a bolded text? [!] in AngelScripting and C++ meant not. The code above is equivalent to...
[if(GetPlayerSanity() LARGER/EQUALS TO 70 AND NOT HasItem("HighSanityLocket"))]

Removed the extra ;. I derped on that one. However, even the debug message of "Locket Looping" isn't appearing (not sure it should from global.hps). And the if statement is what I want (Over 70 Sanity and doesn't have the item -> Give item).
Oh and at the last part. It calls a timer that loops the give item thing. But the one called at the first time (the StartLocketLoop()) doesn't have a timer syntax.
Hmm, I'm not sure the issue is with the loop (although I fixed that), I feel that I can't call scripts like this in the Global file. Sad None of my Debug messages are appearing, even in OnGameStart(), yet my debug messages in each map file are working.
I'm not sure that you can. The global.hps file looks like it keeps track of global variables only.
Um no. I've seen some scripts where the global.hps is used for scripting.
(05-14-2013, 03:08 PM)JustAnotherPlayer Wrote: [ -> ]Um no. I've seen some scripts where the global.hps is used for scripting.

nvm statyk says so

*edit*

I just tried to do some class type thing and it doesn't seem to work in the global sense. Which is what you were going for, I suppose. Now, you could just copy&paste the class to each script file, but that might be arduous/sloppy/beyond the scope of practicality.

PHP Code:
class TestClass
{
  
//Constructor, basically an OnStart
  
TestClass()
  {
    
//This is called when you create an instance of this class
  
}

  
//You can put methods etc beyond this
  //Example of a method
  
void/whatever return type Method(parameters etc)
   {
    
//Do stuff and things
    
}

}

void OnStart() //The actual game script starts here, like always
{
  
//Create an instance of the TestClass class
  
TestClass TestingClass//You can do this outside of OnStart etc, I believe
  
   //You can call methods like so
   
TestingClass.Method(arguments etc)


Like I said, beyond the scope of practicality.
No you can not do regular scripting in the global.hps. Like Tomato Cat said, it is only used to store global variables that can be used to do scripts in local .hps.
Ok, so it can't do so. Can it do the include command by Apjjm?
Pages: 1 2