Frictional Games Forum (read-only)

Full Version: A local variable int bug
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am doing a script fuction using addlocals!
Now the script is supposed to check that the player got 2 variable locals, and when he got those 2 then a function will occur which i did here OnEnter:

PHP Code:
if(GetLocalVarInt("getit") == 2)
 {
    
SetEntityActive("CaveIn_1"true);
    
AddDebugMessage("2globalshavebeenfound"true);
 } 

For the first local, you need to pick up a key which in the callback func of pickup, it will activate this script
PHP Code:
void pickkey(string &in asEntitystring &in asType)
{
    
AddDebugMessage("1global"true);
    
AddLocalVarInt("getit"1);  


And for the 2nd local, you need to use an item on an object by using an adduseitem callback which activates this function here
PHP Code:
void animation(string &in asItemstring &in asEntity)
{
    
RemoveItem(asItem);
    
AddDebugMessage("1global"true);
    
CompleteQuest("bucket""bucket");
    
CreateParticleSystemAtEntity("splashps""ps_impact_water_low.ps"asEntityfalse);
    
PlayGuiSound("mizu"1);
    
GiveItem("wooden_bucket_filled""wooden_bucket_filled""water""wooden_bucket_filled.tga"1);
    
SetMessage("Messages""bucketss"2);
    
AddLocalVarInt("getit"1);  


I added a debug message everytime a player gets a variable, also when the 2 are called as I shown on enter but it does not work. The debug message also doesn't play when it checks "if(GetLocalVarInt("getit") == 2)"

Is there anything wrong or missing that is causing this mind blowing error? When in game there are no errors and crashes that occur while testing this.
The map updates and the script too, so no worries.

thnx
(05-28-2015, 11:09 AM)Mr. Badcatz Wrote: [ -> ]I am doing a script fuction using addlocals!
Now the script is supposed to check that the player got 2 variable locals, and when he got those 2 then a function will occur which i did here OnEnter:

PHP Code:
if(GetLocalVarInt("getit") == 2)
 {
    
SetEntityActive("CaveIn_1"true);
    
AddDebugMessage("2globalshavebeenfound"true);
 } 

This is likely your problem. I remember that OnEnter only runs once when the player enters the map. It does not continue to run forever to check if the state of OnEnter has been fullfilled.

To achieve something that constantly checks if something has been achieved in HPL 2 I think you need to use a very fast timer.
First guess is you're missing SetLocalVarInt(), which should be in OnStart();

PHP Code:
OnStart()
{
SetLocalVarInt("getit"0)


I'm genuinely unsure if that will fix it, but in most cases, you need to either set or declare a variable before it can be modified.


Orr, as Kreek mentioned, throw that section of code after your AddLocalVarInt(); since then it will check if the var does actually equal 2.
Alright, I got it working unexpectedly. So thnx to Rom and u kreek for helping me out with this mind fuck problem. I should learn something from this int he future and thread is now solved.
(05-28-2015, 11:25 AM)(拉赫兰) Romulator Wrote: [ -> ]First guess is you're missing SetLocalVarInt()

Both Set- and Add- LocalVarInt's declare the variable. Add will create it if it doesn't exist, with a default value of 0.

@Badcat: What was it that solved it?
all I had to do is put the
if(GetLocalVarInt("getit") == 2)
{
SetEntityActive("CaveIn_1", true);
AddDebugMessage("2globalshavebeenfound", true);
}
everytime it adds a localvar

And I guess putting a SetLocalVarInt("getit", 0) on start helped too, so kudos for that guys.