Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: How to subtract variables given to units?

  1. #1

    How to subtract variables given to units?

    I have my guy with setvariable ["hunger",90]
    i have a script thats calls this variable (so i can see how hungry my guy is via hint. That works, however my hunger does not increase, nor decrease with anything im doing. Telling me that the variable is staying constant. How does one work around this?




    my hunger script.
    PHP Code:
    #hungerscript
    _target _this select 0;
    _caller _this select 1;
    _id _this select 2;
    ~
    0.125
    _hunger 
    _caller getvariable "hunger";
    ~
    0.125
    if (_hunger 100)THEN {_hunger _hunger+1} ELSE {player setdamage 1};
    ~
    0.125
    if (_hunger >= 90)THEN {hint "You are Starving!} ELSE {};
    ~5
    _caller setvariable ["
    hunger",_hunger];
    goto "
    hungerscript";
    Exit; 
    One day there maybe peace, but there will always be another war....

  2. #2
    Lol I'm surprised people still use SQS.

    Let me suggest an SQF alternative.

    PHP Code:
    _target _this select 0;
    _caller _this select 1;
    _id _this select 2;

    while{
    alive player}do{
       
    _hunger _caller getVaraible "Hunger";
       if(
    _hunger 100)then{_hunger _hunger 1}else{player setDamage 1};
       if(
    _hunger >= 90)then{hint "You are starving!"};
       
    _caller setVariable ["Hunger",_hunger];
       
    sleep 5;

    Having cleaned it up now it will probably work. If not come back and we'll try to figure it out.
    VBS2 Designer

    Quote Originally Posted by Armored_Sheep View Post
    I like to call Arma a sandbox game that works pretty much like LEGO - you buy it not just because you want to have a nice car from the main picture on its box, do you?

  3. #3
    Lance Corporal Stubbinz's Avatar
    Join Date
    Sep 9 2009
    Location
    Colorado
    Posts
    41
    Author of the Thread
    Thank you, and yeah, im old school. ha.
    I don't really know the difference between sqf and sqs very much to be effective with it.

    ---------- Post added at 11:22 PM ---------- Previous post was at 11:17 PM ----------

    And its still not working. ha

  4. #4
    Warrant Officer Demonized's Avatar
    Join Date
    Nov 16 2010
    Location
    Back from afk 2013
    Posts
    2,614
    one of the major differences of sqs and sqf is the way they are executed:
    _null = [something] exec "scriptname.sqs";
    _null = [something] execVM "scriptname.sqf";

    also there is a misspelling in the script Big Dawg KS posted, should be:
    Code:
     _hunger = _caller getVariable "Hunger";
    also im not sure if it matters, but here Hunger is spelled with capital H, not h as you had, maybe its important.

    but yeah, i highly recomend you switch to using sqf, the changes are not that big once you start converting.
    My scripts:
    Spoiler:

    what to do when posting any kind of code dammit!!

    Any new mission editor or scripter in Arma2 should have read Mr Murrays Editing Guide Deluxe at least once, it still applies for A2 even though it was made for Armed Assault.

  5. #5
    Lance Corporal Stubbinz's Avatar
    Join Date
    Sep 9 2009
    Location
    Colorado
    Posts
    41
    Author of the Thread
    Still is not working.
    Funny thing is i have a money variable attached to the unit, and a test script that subtracts its value which seems to be working. Yet, i'm not registering any increase to my hunger value at all as that is supposed to be perpetual in nature. Example, gain +1 hunger every minute or whatever time frame i wanted (going for a minute at the moment). When hunger reaches 100, unit dies. I need it to be compatible for multiplayer, so i cant just use player variable i believe. Its actually really annoying.

  6. #6
    SQS and SQF are very different, and SQS is being phased out.
    http://community.bistudio.com/wiki/S...SQF_conversion
    We must fight - to run away!

  7. #7
    Lance Corporal Stubbinz's Avatar
    Join Date
    Sep 9 2009
    Location
    Colorado
    Posts
    41
    Author of the Thread
    Thanks weirdo for the information, however it doesn't really address the problem i'm having trying to fix my hunger issue ha

  8. #8
    Add -showScriptErrors in your shortcut parameters to see the errors.

    The sqf script had typos, and should probably work when they're fixed:
    Code:
    _target = _this select 0;
    _caller = _this select 1;
    _id = _this select 2;
    
    while {alive player} do {
    	_hunger = _caller getVariable "Hunger";
    	if (_hunger < 100) then {_hunger = _hunger + 1} else {player setDamage 1};
    	if (_hunger >= 90) then {hint "You are starving!"};
    	_caller setVariable ["Hunger",_hunger];
    	sleep 5;
    };

  9. #9
    Warrant Officer Demonized's Avatar
    Join Date
    Nov 16 2010
    Location
    Back from afk 2013
    Posts
    2,614
    maybe the issue is that you try to getVariable the "Hunger" variable to fast, before it is already set, causing script to stall or bug/error?
    there is the option of using getVariable with a default return value.

    try having before the while loop:
    Code:
    waitUntil {(player getVariable ["Hunger", 666]) != 666};
    Edit: above is ofc asuming you have set the variable in init.sqf or somewhere else like a initline or similar, else your issue is that you try to collect a variable wich does not exist, and you shoudl just setVariable to 0 before the while loop.
    FYI: there was a missing ; after the last } in Big Dawg KS´s sqf script.
    for sqf its important to have these, just incase you did not straight copy celerys script wich had this fixed.
    these small typos have caused myself alot of headaches in the past, squint is a nice tool to check for errors as well btw.
    Last edited by Demonized; Jun 21 2011 at 14:01.

  10. #10
    Lol sorry for the typos it's been a while since I wrote SQF. Demonized has a good point I overlooked, the variable may not be initialized.

    Revised (and corrected) script:
    PHP Code:
    _target _this select 0;
    _caller _this select 1;
    _id _this select 2;

    while {
    alive player} do {
        
    _hunger _caller getVariable ["Hunger",0]; // < give hunger a default value of 0
        
    if (_hunger 100then {_hunger _hunger 1} else {player setDamage 1};
        if (
    _hunger >= 90then {hint "You are starving!"};
        
    _caller setVariable ["Hunger",_hunger];
        
    sleep 5;
    }; 


    ---------- Post added at 11:02 AM ---------- Previous post was at 10:59 AM ----------

    Quote Originally Posted by Demonized View Post
    also im not sure if it matters, but here Hunger is spelled with capital H, not h as you had, maybe its important.
    I'm pretty sure that "hunger" and "Hunger" are the same variable. Most variables are case insensitive in the game.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •