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

Thread: variables

  1. #1

    variables

    i trying to get a user defined variable in intgr form to be shared between scripts.

    example.

    Code:
    _amountofbombs      = ctrlText 4;
    if (!(_amountofbombs call ISSE_str_isInteger)) then {_amountofbombs = "0";};
    _amountofbombs      = _amountofbombs call ISSE_str_StrToInt;  
    if (_amountofbombs < 0) then {_amountofbombs = 0;};
    gets the user input fine.

    then

    Code:
    buttonSetAction [3, format["if ((lbCurSel 1) >= 0) then {[(lbData [1, (lbCurSel 1)]), %1, ctrlText 4] execVM ""createbombs.sqf""; closedialog 0; [0,0,0,[%1]] execVM ""bombshopdialog.sqf"";};", _bombshopNum] ];
    calls the next script to activate when button pressed.

    but the next script wont get any variables from previous scripts.

    should i define as follows?

    in first script:
    Code:
    _bombcounter setVariable ["mycounter", _amountofbombs, true];
    in script that activates on button:
    Code:
    _amountofbombs = _bombcounter getVariable "mycounter";
    and do i need to define _bombcounter in my init.sqf?

    or am i just having a brain fart?

    any help welcomed
    Last edited by Scopey; Feb 2 2010 at 22:54.

  2. #2
    bump... any help?? as in will my idea work or another way i can code for the end result..

    id be happier if there was a way the variable could be sent when button pressed

  3. #3
    The function setVariable only works on objects in the game world.

    You want to use public variables, which are any variable that doesnt start with an underscore.

    Also you should prefix any of the variables you use in the public namespace with something unique. For example, for my personal projects i prefix all public variables with "NOU_" and for ACE2 its "ACE_" that way you do not get variable conflicts.

    To make sure you are not stepping on someone elses toes register your prefix tag here: http://www.ofpec.com/tags/

  4. #4
    Hi scopy,

    1-Try using global variables, instead of using _amountofbombs try SCOPY_amountofbombs for example.

    2- too u could try using the player as a container of your variables
    player setVariable ["SCOPY_mycounter", _amountofbombs, true];

    _amountofbombs = player getVariable "SCOPY_mycounter";

    3- U can pas the variable as a parameter to each function

    NOTE:is important that if u use global variables or variables in objects u personalize this like "SCOPY..." to minimice the risk of other script of other people can use the same name.

    I hope this will help u
    Last edited by Monsada; Feb 3 2010 at 08:13.

  5. #5
    Yes, when I said public, I meant global in arma 2 terms... I keep thinking of their scope, but thats not really correct...

  6. #6
    thanx guys... testing now

  7. #7
    Also for your IDC for your controls, remember to make them something unique. You might run into conflicts if you are down in the single digit range. Try something in the 4 or 5 digit range.

  8. #8
    im tired and brain dieing... setting it global???

    publicvariable "SCOPY_mycounter"; ????

    defining to player didnt work...

    Code:
    player setVariable ["SCOPY_mycounter", SCOPY_amountofbombs, true];
    
    SCOPY_amountofbombs = player getVariable "SCOPY_mycounter";
    i have even tired defining it in init.sqf

    10 hours scripting for a release this weekend...grr

    still the first problem is stopping me... but i have made about 20 new scripts working...

  9. #9
    Code:
    //set.sqf
    SCOPY_mycounter = 10;
    Code:
    //get.sqf
    player sideChat format["test: %1", SCOPY_mycounter];
    
    // should spit out: TEST: 10 in game chat

    As long as you don't need to send those variables to all the other clients (as in you only care about the player having his own counter number, whatever), that should work.

  10. #10
    thankyou soo much... that how i had it in the begining... but a spelling mistake and a sore head destroyed me for over 2 hours...lol

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
  •