Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help SetGlobalVarInt not working
serbusfish Offline
Member

Posts: 211
Threads: 75
Joined: Aug 2012
Reputation: 0
#1
SetGlobalVarInt not working

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?

07-03-2016, 09:59 PM
Find Reply
Darkfire Offline
Senior Member

Posts: 366
Threads: 21
Joined: May 2014
Reputation: 15
#2
RE: SetGlobalVarInt not working

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: (Select All)
if(GetLocalVarInt("DRDoor") == 1)
{
SetLevelDoorLocked("level_wood_2"false);

In OnEnter, like this:
PHP Code: (Select All)
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.

(This post was last modified: 07-03-2016, 10:52 PM by Darkfire.)
07-03-2016, 10:50 PM
Find Reply
serbusfish Offline
Member

Posts: 211
Threads: 75
Joined: Aug 2012
Reputation: 0
#3
RE: SetGlobalVarInt not working

(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);

}

(This post was last modified: 07-04-2016, 10:14 AM by serbusfish.)
07-04-2016, 01:12 AM
Find Reply
Lizard Offline
Member

Posts: 174
Threads: 23
Joined: Jul 2012
Reputation: 5
#4
RE: SetGlobalVarInt not working

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

CURRENT PROJECT:
A Fathers Secret == Just started
07-04-2016, 11:04 AM
Find Reply
serbusfish Offline
Member

Posts: 211
Threads: 75
Joined: Aug 2012
Reputation: 0
#5
RE: SetGlobalVarInt not working

(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

07-04-2016, 01:55 PM
Find Reply
Romulator Offline
Not Tech Support ;-)

Posts: 3,623
Threads: 62
Joined: Jan 2013
Reputation: 195
#6
RE: SetGlobalVarInt not working

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/am...ution_flow

Discord: Romulator#0001
[Image: 3f6f01a904.png]
07-04-2016, 02:00 PM
Find Reply
Darkfire Offline
Senior Member

Posts: 366
Threads: 21
Joined: May 2014
Reputation: 15
#7
RE: SetGlobalVarInt not working

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

07-04-2016, 04:30 PM
Find Reply
serbusfish Offline
Member

Posts: 211
Threads: 75
Joined: Aug 2012
Reputation: 0
#8
RE: SetGlobalVarInt not working

(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/am...ution_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?

07-05-2016, 08:35 PM
Find Reply
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#9
RE: SetGlobalVarInt not working

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

07-06-2016, 01:59 AM
Find Reply
Mudbill Offline
Muderator

Posts: 3,816
Threads: 59
Joined: Apr 2013
Reputation: 177
#10
RE: SetGlobalVarInt not working

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.

(This post was last modified: 07-06-2016, 02:28 AM by Mudbill.)
07-06-2016, 02:27 AM
Find Reply




Users browsing this thread: 1 Guest(s)