Frictional Games Forum (read-only)
[SCRIPT] SetGlobalVarInt not working - 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: [SCRIPT] SetGlobalVarInt not working (/thread-50798.html)



SetGlobalVarInt not working - serbusfish - 07-03-2016

The scenario: you start in a map with a door that in the story is locked from the other side. You change map and get to the door in question and unlock it, go through it and now it is unlocked in the original map. This is what I did but it didnt work:

Quote:void OnStart()

{

SetGlobalVarInt("DRDoor",0);
CheckDRDoor();

}

void CheckDRDoor()

{
if(GetLocalVarInt("DRDoor") == 1)
{
SetLevelDoorLocked("level_wood_2", false);
}
}

In the second map once the door is unlocked I simply did


Quote:AddGlobalVarInt("DRDoor", 1);

But when I go back to the first map the door is still locked. The same type of script but a Local not GlobalVar worked in a different scenario so I thought it would work here to?


RE: SetGlobalVarInt not working - Darkfire - 07-03-2016

I think I tried putting a fuction link once too, and it didn't work. (I mean this: OnStart{CheckDRDoor;} )

So I would simply put this
PHP Code:
if(GetLocalVarInt("DRDoor") == 1)
{
SetLevelDoorLocked("level_wood_2"false);

In OnEnter, like this:
PHP Code:
void OnEnter
{

  if(
GetLocalVarInt("DRDoor") == 1)
  {
    
SetLevelDoorLocked("level_wood_2"false);
  }


Everything else should be fine, but be sure to tell if it doesn't work.


RE: SetGlobalVarInt not working - serbusfish - 07-04-2016

(07-03-2016, 10:50 PM)Darkfire Wrote: (snip)

It has to be a global variant as it taking place is across multiple maps, otherwise I would have stuck with the local as I have successfully used it in the past.

Anyway, I discovered 2 flaws with my original script which I fixed, 1) in my 'if' part of the script I had Local instead of Global, and 2) I realised if the command 'SetGlobalVarInt("DRDoor",0);' was in the OnStart section it would reset to 0 every time the map was loaded, so I put it inside one of my collide callbacks instead.

So I fixed these issues but it STILL wont work! This is really frustrating as I actually thought i'd cracked it. Can anyone see what is wrong now? Just for clarity this is what I now have:

map 1#:

Quote:void OnStart()

{
CheckDRDoor();
AddEntityCollideCallback("Player", "ScriptArea_1", "Creak", true, 1);
}

void CheckDRDoor()
{
if(GetGlobalVarInt("DRDoor") == 1)
{
SetLevelDoorLocked("level_wood_2", false);
}
}

void Creak(string &in asParent, string &in asChild, int alState)

{
PlaySoundAtEntity("", "afx_mans_hallquake_postdetail.snt", "ScriptArea_4", 0, false);
StartScreenShake(0.02f, 4.0f, 1.5f, 3.0f);
SetGlobalVarInt("DRDoor",0);
CreateParticleSystemAtEntity("", "ps_dust_falling_mansion_quake_landing.ps", "AreaDust_1", false);
CreateParticleSystemAtEntity("", "ps_dust_falling_mansion_quake_landing.ps", "AreaDust_2", false);
CreateParticleSystemAtEntity("", "ps_dust_falling_mansion_quake_landing.ps", "AreaDust_3", false);
CreateParticleSystemAtEntity("", "ps_dust_falling_mansion_quake_landing.ps", "AreaDust_4", false);
}

map #2:

Quote:void OnStart()
{
SetEntityPlayerInteractCallback("ExamineArea_1", "UnlockDoor", true);
}

void UnlockDoor(string &in asEntity)

{
SetMessage("Messages", "DoorNowUnlocked", 3);
PlaySoundAtEntity("", "lock_door.snt", "level_wood_5", 0, false);
SetEntityActive("ExamineArea_1", false);
AddGlobalVarInt("DRDoor", 1);

}



RE: SetGlobalVarInt not working - Lizard - 07-04-2016

you have CheckDRDoor(); in OnStart, which means it only gets checked the first time you enter the map.

Try to put it in OnEnter instead


RE: SetGlobalVarInt not working - serbusfish - 07-04-2016

(07-04-2016, 11:04 AM)ZereboO Wrote: you have CheckDRDoor(); in OnStart, which means it only gets checked the first time you enter the map.

Try to put it in OnEnter instead

I didn't know the OnStart section was only used once?

I any case I have just finally managed to fix the issue! I created a collide callback where the player starts for the second time, so as soon as the level loads the check is called and the door unlocks Big Grin


RE: SetGlobalVarInt not working - Romulator - 07-04-2016

OnStart(); is called when you first load the map. OnEnter() is called every time you enter the map.

There's an awesome page on the wiki on Execution Flow which talks about the sequence of loading things. Take a look if you get some spare time!

https://wiki.frictionalgames.com/hpl2/amnesia/script_language_reference_and_guide/execution_flow


RE: SetGlobalVarInt not working - Darkfire - 07-04-2016

I totally didn't notice that you used GetLocalVar instead of GetGlobalVar. Quite dumb of me.


RE: SetGlobalVarInt not working - serbusfish - 07-05-2016

(07-04-2016, 02:00 PM)Romulator Wrote: OnStart(); is called when you first load the map. OnEnter() is called every time you enter the map.

There's an awesome page on the wiki on Execution Flow which talks about the sequence of loading things. Take a look if you get some spare time!

https://wiki.frictionalgames.com/hpl2/amnesia/script_language_reference_and_guide/execution_flow

Cheers for that. So can I ask something (probably dumb but I need to know), if say the player loads the map, saves and quits, then reloads later on, will the OnStart section be used again in this instance?


RE: SetGlobalVarInt not working - Daemian - 07-06-2016

Nope. I don't think so. You can always try it to be sure.


RE: SetGlobalVarInt not working - Mudbill - 07-06-2016

OnStart and OnEnter are not executed upon loading an already entered level via the save function as far as I've tried. But timers do freeze and continue where they left off, so if you have a looping timer it will still loop after you load it, which can be used.