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
Scripts with AddLocalVarInt
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#1
Scripts with AddLocalVarInt

I've got one last script to complete until my custom story is finished. However I cannot get it to work. This is how I intended it to be.

1. Pull a lever (collide script) and you will get AddLocalVarInt

2. Then I've made a script that checks if the player has this localvarint, which he now got.

3. Now, a timer SHOULD start and play a sound + shake the entire room.

Now the last thing does not happen. I would think I'm not supposed to use AddLocalVarInt. But what am I supposed to use instead? Script down below incase you need it. I'm very sorry if I might confuse you with my english, but I cannot help it Sad

//Western piston
void ActivateWestPiston(string &in asParent, string &in asChild, int alState)
{
SetMoveObjectState("barrier_piston_1", -0.3);
PlaySoundAtEntity("", "17_piston_move", "barrier_piston_1", 1.0f, false);
SetEntityInteractionDisabled("button_simple_4", true);

AddLocalVarInt("EastPiston", 1);
}
//Eastern piston
void ActivateEastPiston(string &in asParent, string &in asChild, int alState)
{
SetMoveObjectState("barrier_piston_2", -0.3);
PlaySoundAtEntity("", "17_piston_move", "barrier_piston_2", 1.0f, false);
SetEntityInteractionDisabled("button_simple_3", true);

AddLocalVarInt("WestPiston", 1);
}
//Pour down the potion in the machine
void PotionOnMachine(string &in asItem, string &in asEntity)
{
GiveSanityBoostSmall();
SetMessage("Messages", "PotionPouredDown", 0);
RemoveItem(asItem);

GiveItemFromFile("glass_container_1", "glass_container.ent");

AddLocalVarInt("PotionPoured", 1);

//The pistons are pulled and the potion has been poured in the machine
if(GetLocalVarInt("WestPiston")==1)
{
AddTimer("explosion", 3.0f, "TimerMachineTheme");
AddTimer("quests", 9.0f, "TimerMachineTheme");

SetEntityActive("ScriptArea_1", false);
SetEntityActive("AreaGetPotionBack", false);
}
}
//The timer for the machine
void TimerMachineTheme(string &in asTimer)
{
if(asTimer == "explosion"){
PlaySoundAtEntity("implodoelexplodo", "27_orb_implode.snt", "Player", 0.0f, false);
StartScreenShake(0.2f, 6, 0.5f, 3);
}
if(asTimer == "quests"){
//Complete all quests that has anything to do with this
CompleteQuest("MagicPotionFail", "MagicPotionFail");
CompleteQuest("PotionPourDownManual", "PotionPourDownManual");
CompleteQuest("BrokenButtonsDownstairs", "BrokenButtonsDownstairs");

GiveSanityBoostSmall();
PlayMusic("13_puzzle_machine.ogg", false, 1.0f, 0.5f, 10, false);

SetGlobalVarInt("BarrierMachineFixed", 1);
}
}
06-12-2013, 08:08 PM
Find
Bridge Offline
Posting Freak

Posts: 1,971
Threads: 25
Joined: May 2012
Reputation: 128
#2
RE: Scripts with AddLocalVarInt

If all you're doing with these variables is checking whether they are equal to 0 or 1 you could save some space by just using Boolean variables.
06-12-2013, 09:14 PM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#3
RE: Scripts with AddLocalVarInt

But this worked perfectly the first time I tried it. Then I tried again and nothing wanted to work anymore
06-12-2013, 09:30 PM
Find
Bridge Offline
Posting Freak

Posts: 1,971
Threads: 25
Joined: May 2012
Reputation: 128
#4
RE: Scripts with AddLocalVarInt

Well I don't know what's wrong with your script but seeing as integers generally take up 4 bytes and Boolean variables only 1 you save a whole bunch of space that otherwise goes towards doing nothing. A good general rule of thumb is to use as few resources as you possibly can to achieve what you want. Doesn't do anything to make your code more functional, just more efficient.
(This post was last modified: 06-12-2013, 10:00 PM by Bridge.)
06-12-2013, 09:59 PM
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#5
RE: Scripts with AddLocalVarInt

You may want to use SetLocalVarInt rather than AddLocalVarInt - 'Set' merely sets the variable you specify to the value you specify, wheras 'Add' actually adds the value you specify to the total that the variable holds. That should explain why it worked the first time, although there might be another problem as well.

SetLocalVarInt("Int", 1);
AddLocalVarInt("Int", 1);
// "Int" now equals 2

SetLocalVarInt("Int", 1);
SetLocalVarInt("Int", 1);
// "Int" still equals 1

(06-12-2013, 09:59 PM)Bridge Wrote: Well I don't know what's wrong with your script but seeing as integers generally take up 4 bytes and Boolean variables only 1 you save a whole bunch of space that otherwise goes towards doing nothing. A good general rule of thumb is to use as few resources as you possibly can to achieve what you want. Doesn't do anything to make your code more functional, just more efficient.

The potential problem with using a bool is that there is no engine function to set a bool variable, and only variables set by the engine functions will be saved when you exit/reload your game. Any variables declared simply using bool MyBool = true; in the global scope of the script will therefore be re-initialized when the map reloads. It could then present some weird behaviors for the puzzle if the player saves & exits, or just goes out of the map and back in, although your absolutely right if that risk is managed correctly

(This post was last modified: 06-13-2013, 12:31 PM by Adrianis.)
06-13-2013, 12:25 PM
Find
Bridge Offline
Posting Freak

Posts: 1,971
Threads: 25
Joined: May 2012
Reputation: 128
#6
RE: Scripts with AddLocalVarInt

(06-13-2013, 12:25 PM)Adrianis Wrote: You may want to use SetLocalVarInt rather than AddLocalVarInt - 'Set' merely sets the variable you specify to the value you specify, wheras 'Add' actually adds the value you specify to the total that the variable holds. That should explain why it worked the first time, although there might be another problem as well.

SetLocalVarInt("Int", 1);
AddLocalVarInt("Int", 1);
// "Int" now equals 2

SetLocalVarInt("Int", 1);
SetLocalVarInt("Int", 1);
// "Int" still equals 1

(06-12-2013, 09:59 PM)Bridge Wrote: Well I don't know what's wrong with your script but seeing as integers generally take up 4 bytes and Boolean variables only 1 you save a whole bunch of space that otherwise goes towards doing nothing. A good general rule of thumb is to use as few resources as you possibly can to achieve what you want. Doesn't do anything to make your code more functional, just more efficient.

The potential problem with using a bool is that there is no engine function to set a bool variable, and only variables set by the engine functions will be saved when you exit/reload your game. Any variables declared simply using bool MyBool = true; in the global scope of the script will therefore be re-initialized when the map reloads. It could then present some weird behaviors for the puzzle if the player saves & exits, or just goes out of the map and back in, although your absolutely right if that risk is managed correctly

Well I'm used to working low-level where I would just save the data to an external data type and read the latest value in each time the program starts. I understand now why SetLocalVarInt and its equivalents are necessary in this situation though. Thanks for the explanation.
06-13-2013, 10:09 PM
Find




Users browsing this thread: 2 Guest(s)