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
Help with variable ints!
Radical Batz Offline
Posting Freak

Posts: 953
Threads: 145
Joined: Dec 2013
Reputation: 25
#1
Help with variable ints!

I'm kinda getting confused sometimes with if(GetLocalVarInts

and I kinda want some help form you guys to teach me how to exactly use them pls! or where to place them.

I'm kinda making this code where you have a dirty container and if you turn the wheel on the water barrel it will display a message "I must put the container first" so then when you put the container, you can turn the wheel and you have cleaned the container and now you can use it on the other barrels, but that code is already done.

So this is the confusing part, if you haven't used the container on the water barrel yet and try to place the container on the floor under the other barrels it will display a message "I must clean the container first" so you're supposed to use it on the water barrel first and when you used it on the water barrel then now you can place the container under the other barrels! that's all but it's kinda confusing to me when I do the "if(GetLocalVarInts"
so if you guys can help me then I would be really appreciated! Smile

(This post was last modified: 03-19-2014, 10:06 AM by Radical Batz.)
03-19-2014, 10:05 AM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#2
RE: Help with variable ints!

It's like this:
PHP Code: (Select All)
void ContainerOnBarrelCheck()
{
if(
GetLocalVarInt("BarrelCheck") == 1)
{
//WHAT TO DO IF BARREL IS ALREADY CLEANED
}

else if(
GetLocalVarInt("BarrelCheck") != 1)
{
//WHAT TO DO IF BARREL HAVEN'T CLEANED YET
}


Let's just say that you have a Local Var Int of 0 named BarrelCheck. Now if you already used the container on the water barrel then add one by AddLocalVarInt. But if you haven't then nothing happened right? The VarInt didn't get plus one.

In the function where you can add the LocalVarInt add this line:
PHP Code: (Select All)
ContainerOnBarrelCheck(); 

So that when the VarInt is added by one, the script also checks the above code whether the VarInt is 1 or not. If it's 1 then something happens. But if it's not one (!= 1) then nothing happens.

"Veni, vidi, vici."
"I came, I saw, I conquered."
03-19-2014, 10:15 AM
Find
Radical Batz Offline
Posting Freak

Posts: 953
Threads: 145
Joined: Dec 2013
Reputation: 25
#3
RE: Help with variable ints!

Like this right? sorry if I'm wrong or not I just woke up right now and I've got a splitting headache XD

PHP Code: (Select All)
void OnStart()
{
    
    
PlayMusic("04_amb.ogg"true141true);
    
AddTimer("AreaScrape_"RandFloat(3.0f,10.f), "TimerAreaScrape");
    
AddTimer("AreaStep_"RandFloat(3.0f,10.f), "TimerAreaStep");
    
AddUseItemCallback("""DirtyContainer""PutCont""UseContainer"true);
    
AddEntityCollideCallback("Player""AreaDoor""EventDoor"true1);    
    
    


}

void TimerAreaScrape(string &in asTimer)
{
    
int iRand RandInt(16);

    
PlaySoundAtEntity(asTimer+iRand"15_wall_crawl.snt"asTimer+iRand1false);
    
AddTimer("EndRadial"4.0f"TimerEndRadial");
    
AddTimer(asTimerRandFloat(15.0f30.0f), "TimerAreaScrape");
}

void TimerAreaStep(string &in asTimer)
{
    
int iRand RandInt(16);

    
PlaySoundAtEntity(asTimer+iRand"scare_wood_creak_walk.snt"asTimer+iRand1false);
    
AddTimer("EndRadial"4.0f"TimerEndRadial");
    
AddTimer(asTimerRandFloat(15.0f30.0f), "TimerAreaStep");
}

void EventDoor(string &in asParentstring &in asChildint alState)
{
        
SetSwingDoorClosed("Door"falsefalse);
        
SetSwingDoorDisableAutoClose("Door"true);
 
        
PlaySoundAtEntity("creak""joint_door_move_special.snt""Door"1false);
    
PlaySoundAtEntity("Wind""general_wind_whirl""Player"2false);
    
PlaySoundAtEntity("scare""react_scare.snt""Player"0.75ffalse);
    
PlaySoundAtEntity("SoundBong""scare_tingeling.snt""Player"0.0ffalse);
    
PlayMusic("18_amb.ogg"true1.0f00true);
    
CreateParticleSystemAtEntity("PSDoor_3""ps_dust_push.ps""Door"false);
    
CreateParticleSystemAtEntity("PSDoor_4""ps_dust_push.ps""Door"false);
    
GiveSanityDamage(10true);    
 
        
AddTimer(""2"TimerStopSound");
        
AddTimer("Door"0"TimerMoveDoor");
}
 
void TimerMoveDoor(string &in asTimer)
{
        if(
GetLocalVarInt("VarDoor") == 50) return;
        
AddLocalVarInt("VarDoor"1);
 
        
AddTimer(asTimer0.03"TimerMoveDoor");
 
        
AddPropForce(asTimer7000"world");
}
 
void TimerStopSound(string &in asTimer)
{
        
StopSound("creak"0.4);
}

void TurnLiquidValve(string &in asEntityNameint alState)
{
 if(
alState == 1)
 {
  
CreateParticleSystemAtEntity("liquidps""ps_liquid_epoxy.ps""PS"false);
  
CreateParticleSystemAtEntity("splat""ps_liquid_epoxy_splatt.ps""PS_1"true);
 
  
PlaySoundAtEntity("turnon""12_valve_stuck"asEntityName0false);
  
  
PlaySoundAtEntity("hdfg""12_epoxy_flow"asEntityName0true);
   
  
AddTimer("fillcontainer"5.0f"TimerFillContainer");
 }
}

void TimerFillContainer(string &in asTimer)
{
 
SetPropActiveAndFade("Empty"false0.5f);
 
SetPropActiveAndFade("Clean"true0.5f);
SetEntityActive("PutCont"false);
AddPlayerSanity(2);
}

void InteractCallback(string &in asEntity)
{
 if(
GetLocalVarInt("ContainerUsed") == 0SetMessage("Messages""Place"0);
            return; 
//Stops the script completely
 
 
SetWheelStuckState("ValveStuck"0false);
}

void UseContainer(string &in asEntitystring &in asItem)
{
 
PlaySoundAtEntity("plss""puzzle_place_jar"asEntity0.0ffalse);
SetWheelStuckState("ValveStuck"0true);
 
 
SetEntityActive("Empty"true);
 
SetLocalVarInt("ContainerUsed"1);
}



void TurnLiquidValve2(string &in asEntityNameint alState)
{
 if(
alState == 1)
 {
  
CreateParticleSystemAtEntity("liquidps""ps_liquid_epoxy.ps""PS"false);
  
CreateParticleSystemAtEntity("splat""ps_liquid_epoxy_splatt.ps""PS_1"true);
 
  
PlaySoundAtEntity("turnon""12_valve_stuck"asEntityName0false);
  
  
PlaySoundAtEntity("hdfg""12_epoxy_flow"asEntityName0true);
   
  
AddTimer("fillcontainer"5.0f"TimerFillContainer");
 }
}

void TimerFillContainer(string &in asTimer)
{
 
SetPropActiveAndFade("Empty_1"false0.5f);
 
SetPropActiveAndFade("Fill"true0.5f);
SetEntityActive("PutCont_1"false);
AddPlayerSanity(2);
}

void ContainerOnBarrelCheck()
{
if(
GetLocalVarInt("Clean") == 1)
{
//WHAT TO DO IF BARREL IS ALREADY CLEANED
}

else if(
GetLocalVarInt("DirtyContainer") != 1)
{
//WHAT TO DO IF BARREL HAVEN'T CLEANED YET
}

void UseContainer(string &in asEntitystring &in asItem)
{
 
PlaySoundAtEntity("plss""puzzle_place_jar"asEntity0.0ffalse);
SetWheelStuckState("StuckValve"0true);
 
 
SetEntityActive("Empty"true);
 
SetLocalVarInt("ContainerUsed"1);


03-19-2014, 10:24 AM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#4
RE: Help with variable ints!

Yes, but my code is missing a closing } brace. Also put the SetLocalVarInt in the OnStart

"Veni, vidi, vici."
"I came, I saw, I conquered."
03-19-2014, 10:32 AM
Find
Radical Batz Offline
Posting Freak

Posts: 953
Threads: 145
Joined: Dec 2013
Reputation: 25
#5
RE: Help with variable ints!

actually it's not, it looks correct to me
PHP Code: (Select All)
void ContainerOnBarrelCheck()
{
if(
GetLocalVarInt("Clean") == 1)
{
//WHAT TO DO IF BARREL IS ALREADY CLEANED
}

else if(
GetLocalVarInt("DirtyContainer") != 1)
{
//WHAT TO DO IF BARREL HAVEN'T CLEANED YET


and by set local variant on void on start, you mean like adduseitem callback or addentitycollide callback? because I never added a setlocal varint on void on start and I don't know what that means yet XD since I'm new to local varints

(This post was last modified: 03-19-2014, 10:40 AM by Radical Batz.)
03-19-2014, 10:38 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#6
RE: Help with variable ints!

It is missing one at the bottom:
PHP Code: (Select All)
void ContainerOnBarrelCheck()
{
    if(
GetLocalVarInt("Clean") == 1)
    {
        
//WHAT TO DO IF BARREL IS ALREADY CLEANED
    
}

    else if(
GetLocalVarInt("DirtyContainer") != 1)
    {
        
//WHAT TO DO IF BARREL HAVEN'T CLEANED YET
    
}
}
//<- this one 

Remember that any opening brace needs a closing brace. If you see an odd number of braces, something's missing.

By the way, you could just leave it as "else" without the second if statement. It would ultimately do the same thing, just be a bit shorter.

I just noticed you use a different name for the two variables in the check. Is this intentional? Because it was the same originally.

(This post was last modified: 03-19-2014, 12:20 PM by Mudbill.)
03-19-2014, 12:16 PM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#7
RE: Help with variable ints!

(03-19-2014, 12:16 PM)Mudbill Wrote: It is missing one at the bottom:
PHP Code: (Select All)
void ContainerOnBarrelCheck()
{
    if(
GetLocalVarInt("Clean") == 1)
    {
        
//WHAT TO DO IF BARREL IS ALREADY CLEANED
    
}

    else if(
GetLocalVarInt("DirtyContainer") != 1)
    {
        
//WHAT TO DO IF BARREL HAVEN'T CLEANED YET
    
}
}
//<- this one 

Remember that any opening brace needs a closing brace. If you see an odd number of braces, something's missing.

By the way, you could just leave it as "else" without the second if statement. It would ultimately do the same thing, just be a bit shorter.

I just noticed you use a different name for the two variables in the check. Is this intentional? Because it was the same originally.

Tbh I use else if's because if I want if a VarInt is 2 or 1 or 0, more than one.

Also, you need to put this into the OnStart section.
PHP Code: (Select All)
SetLocalVarInt("BarrelCheck"0); 

"Veni, vidi, vici."
"I came, I saw, I conquered."
(This post was last modified: 03-19-2014, 01:04 PM by PutraenusAlivius.)
03-19-2014, 01:02 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#8
RE: Help with variable ints!

Yeah, else-if's are useful, no doubt. But a normal else-statement simply triggers if the prior if-statement does not. In this case, the else keyword could even be left out since the if-statement checks for everything BUT 1.

I suppose it falls mostly on preference though.

Either way, I suppose the int to put in OnStart should match what he renamed them? I suspect he shouldn't have renamed them though, or at least keep them both the same. "BarrelCheck" is a nice example.

(This post was last modified: 03-19-2014, 01:24 PM by Mudbill.)
03-19-2014, 01:23 PM
Find
Radical Batz Offline
Posting Freak

Posts: 953
Threads: 145
Joined: Dec 2013
Reputation: 25
#9
RE: Help with variable ints!

Ok I made the original I did not rename them this time, so is this supposed to work in game now? should I name the containers BarrelCheck or the script boxes that I am going to put the container on?

PHP Code: (Select All)
void OnStart()
{
    
    
PlayMusic("04_amb.ogg"true141true);
    
AddTimer("AreaScrape_"RandFloat(3.0f,10.f), "TimerAreaScrape");
    
AddTimer("AreaStep_"RandFloat(3.0f,10.f), "TimerAreaStep");
    
AddUseItemCallback("""DirtyContainer""PutCont""UseContainer"true);
    
AddEntityCollideCallback("Player""AreaDoor""EventDoor"true1);
    
SetLocalVarInt("BarrelCheck"0);     
    
    


}

void TimerAreaScrape(string &in asTimer)
{
    
int iRand RandInt(16);

    
PlaySoundAtEntity(asTimer+iRand"15_wall_crawl.snt"asTimer+iRand1false);
    
AddTimer("EndRadial"4.0f"TimerEndRadial");
    
AddTimer(asTimerRandFloat(15.0f30.0f), "TimerAreaScrape");
}

void TimerAreaStep(string &in asTimer)
{
    
int iRand RandInt(16);

    
PlaySoundAtEntity(asTimer+iRand"scare_wood_creak_walk.snt"asTimer+iRand1false);
    
AddTimer("EndRadial"4.0f"TimerEndRadial");
    
AddTimer(asTimerRandFloat(15.0f30.0f), "TimerAreaStep");
}

void EventDoor(string &in asParentstring &in asChildint alState)
{
        
SetSwingDoorClosed("Door"falsefalse);
        
SetSwingDoorDisableAutoClose("Door"true);
 
        
PlaySoundAtEntity("creak""joint_door_move_special.snt""Door"1false);
    
PlaySoundAtEntity("Wind""general_wind_whirl""Player"2false);
    
PlaySoundAtEntity("scare""react_scare.snt""Player"0.75ffalse);
    
PlaySoundAtEntity("SoundBong""scare_tingeling.snt""Player"0.0ffalse);
    
PlayMusic("18_amb.ogg"true1.0f00true);
    
CreateParticleSystemAtEntity("PSDoor_3""ps_dust_push.ps""Door"false);
    
CreateParticleSystemAtEntity("PSDoor_4""ps_dust_push.ps""Door"false);
    
GiveSanityDamage(10true);    
 
        
AddTimer(""2"TimerStopSound");
        
AddTimer("Door"0"TimerMoveDoor");
}
 
void TimerMoveDoor(string &in asTimer)
{
        if(
GetLocalVarInt("VarDoor") == 50) return;
        
AddLocalVarInt("VarDoor"1);
 
        
AddTimer(asTimer0.03"TimerMoveDoor");
 
        
AddPropForce(asTimer7000"world");
}
 
void TimerStopSound(string &in asTimer)
{
        
StopSound("creak"0.4);
}

void TurnLiquidValve(string &in asEntityNameint alState)
{
 if(
alState == 1)
 {
  
CreateParticleSystemAtEntity("liquidps""ps_liquid_epoxy.ps""PS"false);
  
CreateParticleSystemAtEntity("splat""ps_liquid_epoxy_splatt.ps""PS_1"true);
 
  
PlaySoundAtEntity("turnon""12_valve_stuck"asEntityName0false);
  
  
PlaySoundAtEntity("hdfg""12_epoxy_flow"asEntityName0true);
   
  
AddTimer("fillcontainer"5.0f"TimerFillContainer");
 }
}

void TimerFillContainer(string &in asTimer)
{
 
SetPropActiveAndFade("Empty"false0.5f);
 
SetPropActiveAndFade("Clean"true0.5f);
SetEntityActive("PutCont"false);
AddPlayerSanity(2);
}

void InteractCallback(string &in asEntity)
{
 if(
GetLocalVarInt("ContainerUsed") == 0SetMessage("Messages""Place"0);
            return; 
//Stops the script completely
 
 
SetWheelStuckState("ValveStuck"0false);
}

void UseContainer(string &in asEntitystring &in asItem)
{
 
PlaySoundAtEntity("plss""puzzle_place_jar"asEntity0.0ffalse);
SetWheelStuckState("ValveStuck"0true);
 
 
SetEntityActive("Empty"true);
 
SetLocalVarInt("ContainerUsed"1);
}


void ContainerOnBarrelCheck()
{
    if(
GetLocalVarInt("BarrelCheck") == 1)
    {
        
//WHAT TO DO IF BARREL IS ALREADY CLEANED
    
}

    else if(
GetLocalVarInt("BarrelCheck") != 1)
    {
        
//WHAT TO DO IF BARREL HAVEN'T CLEANED YET
    
}
}
//<- this one 

03-19-2014, 01:40 PM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#10
RE: Help with variable ints!

(03-19-2014, 01:40 PM)Badcat5550 Wrote: Ok I made the original I did not rename them this time, so is this supposed to work in game now? should I name the containers BarrelCheck or the script boxes that I am going to put the container on?

PHP Code: (Select All)
void OnStart()
{
    
    
PlayMusic("04_amb.ogg"true141true);
    
AddTimer("AreaScrape_"RandFloat(3.0f,10.f), "TimerAreaScrape");
    
AddTimer("AreaStep_"RandFloat(3.0f,10.f), "TimerAreaStep");
    
AddUseItemCallback("""DirtyContainer""PutCont""UseContainer"true);
    
AddEntityCollideCallback("Player""AreaDoor""EventDoor"true1);
    
SetLocalVarInt("BarrelCheck"0);     
    
    


}

void TimerAreaScrape(string &in asTimer)
{
    
int iRand RandInt(16);

    
PlaySoundAtEntity(asTimer+iRand"15_wall_crawl.snt"asTimer+iRand1false);
    
AddTimer("EndRadial"4.0f"TimerEndRadial");
    
AddTimer(asTimerRandFloat(15.0f30.0f), "TimerAreaScrape");
}

void TimerAreaStep(string &in asTimer)
{
    
int iRand RandInt(16);

    
PlaySoundAtEntity(asTimer+iRand"scare_wood_creak_walk.snt"asTimer+iRand1false);
    
AddTimer("EndRadial"4.0f"TimerEndRadial");
    
AddTimer(asTimerRandFloat(15.0f30.0f), "TimerAreaStep");
}

void EventDoor(string &in asParentstring &in asChildint alState)
{
        
SetSwingDoorClosed("Door"falsefalse);
        
SetSwingDoorDisableAutoClose("Door"true);
 
        
PlaySoundAtEntity("creak""joint_door_move_special.snt""Door"1false);
    
PlaySoundAtEntity("Wind""general_wind_whirl""Player"2false);
    
PlaySoundAtEntity("scare""react_scare.snt""Player"0.75ffalse);
    
PlaySoundAtEntity("SoundBong""scare_tingeling.snt""Player"0.0ffalse);
    
PlayMusic("18_amb.ogg"true1.0f00true);
    
CreateParticleSystemAtEntity("PSDoor_3""ps_dust_push.ps""Door"false);
    
CreateParticleSystemAtEntity("PSDoor_4""ps_dust_push.ps""Door"false);
    
GiveSanityDamage(10true);    
 
        
AddTimer(""2"TimerStopSound");
        
AddTimer("Door"0"TimerMoveDoor");
}
 
void TimerMoveDoor(string &in asTimer)
{
        if(
GetLocalVarInt("VarDoor") == 50) return;
        
AddLocalVarInt("VarDoor"1);
 
        
AddTimer(asTimer0.03"TimerMoveDoor");
 
        
AddPropForce(asTimer7000"world");
}
 
void TimerStopSound(string &in asTimer)
{
        
StopSound("creak"0.4);
}

void TurnLiquidValve(string &in asEntityNameint alState)
{
 if(
alState == 1)
 {
  
CreateParticleSystemAtEntity("liquidps""ps_liquid_epoxy.ps""PS"false);
  
CreateParticleSystemAtEntity("splat""ps_liquid_epoxy_splatt.ps""PS_1"true);
 
  
PlaySoundAtEntity("turnon""12_valve_stuck"asEntityName0false);
  
  
PlaySoundAtEntity("hdfg""12_epoxy_flow"asEntityName0true);
   
  
AddTimer("fillcontainer"5.0f"TimerFillContainer");
 }
}

void TimerFillContainer(string &in asTimer)
{
 
SetPropActiveAndFade("Empty"false0.5f);
 
SetPropActiveAndFade("Clean"true0.5f);
SetEntityActive("PutCont"false);
AddPlayerSanity(2);
}

void InteractCallback(string &in asEntity)
{
 if(
GetLocalVarInt("ContainerUsed") == 0SetMessage("Messages""Place"0);
            return; 
//Stops the script completely
 
 
SetWheelStuckState("ValveStuck"0false);
}

void UseContainer(string &in asEntitystring &in asItem)
{
 
PlaySoundAtEntity("plss""puzzle_place_jar"asEntity0.0ffalse);
SetWheelStuckState("ValveStuck"0true);
 
 
SetEntityActive("Empty"true);
 
SetLocalVarInt("ContainerUsed"1);
}


void ContainerOnBarrelCheck()
{
    if(
GetLocalVarInt("BarrelCheck") == 1)
    {
        
//WHAT TO DO IF BARREL IS ALREADY CLEANED
    
}

    else if(
GetLocalVarInt("BarrelCheck") != 1)
    {
        
//WHAT TO DO IF BARREL HAVEN'T CLEANED YET
    
}
}
//<- this one 

You have to call the ContainerOnBarrelCheck() function in the callback function that you use to increment the VarInt by one.

Use this to call it;
ContainerOnBarrelCheck();

"Veni, vidi, vici."
"I came, I saw, I conquered."
03-19-2014, 01:50 PM
Find




Users browsing this thread: 1 Guest(s)