Cyfiawn
Junior Member
Posts: 27
Threads: 8
Joined: Jun 2012
Reputation:
0
|
Using Global.hps to use a script in every level
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
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
(This post was last modified: 05-14-2013, 11:44 AM by Cyfiawn.)
|
|
05-14-2013, 11:38 AM |
|
PutraenusAlivius
Posting Freak
Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation:
119
|
RE: Using Global.hps to use a script in every level
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"))]
"Veni, vidi, vici."
"I came, I saw, I conquered."
|
|
05-14-2013, 12:39 PM |
|
Cyfiawn
Junior Member
Posts: 27
Threads: 8
Joined: Jun 2012
Reputation:
0
|
RE: Using Global.hps to use a script in every level
(05-14-2013, 12:39 PM)JustAnotherPlayer Wrote: 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).
|
|
05-14-2013, 01:20 PM |
|
PutraenusAlivius
Posting Freak
Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation:
119
|
RE: Using Global.hps to use a script in every level
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.
"Veni, vidi, vici."
"I came, I saw, I conquered."
|
|
05-14-2013, 02:45 PM |
|
Cyfiawn
Junior Member
Posts: 27
Threads: 8
Joined: Jun 2012
Reputation:
0
|
RE: Using Global.hps to use a script in every level
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. None of my Debug messages are appearing, even in OnGameStart(), yet my debug messages in each map file are working.
|
|
05-14-2013, 03:01 PM |
|
Tomato Cat
Senior Member
Posts: 287
Threads: 2
Joined: Sep 2012
Reputation:
20
|
RE: Using Global.hps to use a script in every level
I'm not sure that you can. The global.hps file looks like it keeps track of global variables only.
|
|
05-14-2013, 03:06 PM |
|
PutraenusAlivius
Posting Freak
Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation:
119
|
RE: Using Global.hps to use a script in every level
Um no. I've seen some scripts where the global.hps is used for scripting.
"Veni, vidi, vici."
"I came, I saw, I conquered."
|
|
05-14-2013, 03:08 PM |
|
Tomato Cat
Senior Member
Posts: 287
Threads: 2
Joined: Sep 2012
Reputation:
20
|
RE: Using Global.hps to use a script in every level
(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.
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.
(This post was last modified: 05-14-2013, 07:22 PM by Tomato Cat.)
|
|
05-14-2013, 04:58 PM |
|
Statyk
Schrödinger's Mod
Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation:
241
|
RE: Using Global.hps to use a script in every level
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.
|
|
05-14-2013, 06:44 PM |
|
PutraenusAlivius
Posting Freak
Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation:
119
|
RE: Using Global.hps to use a script in every level
Ok, so it can't do so. Can it do the include command by Apjjm?
"Veni, vidi, vici."
"I came, I saw, I conquered."
|
|
05-15-2013, 01:26 AM |
|
|