UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

how to get a variables value from another function [SOLVED]

broken avatar :(
Created 9 months ago
by Phil168912
0 Members and 1 Guest are viewing this topic.
206 views
broken avatar :(
×
broken avatar :(
Location: englandlondon
Date Registered: 16 November 2020
Last active: 4 days ago
Posts
47
Respect
Forum Rank
Legless Crawler
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
×
Phil168912's Groups
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Solved by HitmanVere informing me that the variable needs to be a global one which is done by either "level or self". i went with level i.e level.bank = 0; & it worked.

deposit()
{
   bank = 0;

   deposit_trig = getEnt("deposit", "targetname");
   deposit_trig setCursorHint("HINT_NOICON");
   deposit_trig setHintString("deposit");

   while ( true )
   {
      deposit_trig waittill("trigger", player);

      if(bank < 10000)
      {
         if(player.score >= 100)
         {
            player maps\_zombiemode_score::minus_to_player_score( 100 );
            iPrintLnBold("100 deposited");
         }
      }
      wait .5;
   }
   return bank; //most likely using this wrong
   thread withdraw();

   // I use the trigger once & the bank value has now gone from 0, to 100 for example.
}

   //So...

withdraw()
{
   // How do i define 'bank' in this function with its newly updated value, being which is '100'.

   depositbank = ::deposit; //most likely using this wrong
   [[depositbank]](bank); //most likely using this wrong

   withdrawal_trig = getEnt("withdrawal_trig", "targetname");
   withdrawal_trig setCursorHint("HINT_NOICON");
   withdrawal_trig setHintString("withdrawal");

   while ( true )
   {
      withdrawal_trig waittill("trigger", player);

      if(bank >= 100) //Coz i get 'uninitialised variable for 'bank' on this line.
      {
         player maps\_zombiemode_score::add_to_player_score( 100 );
         iPrintLnBold("100 withdrawn");
      }
   }
}

Double Post Merge: January 02, 2021, 11:16:54 am

so i tried this approach and hit another snag yet again;
& id still like to know "how to get a variables value from another function".

EDIT: **for anyone reading this who may want a simple bank script then the below code works by adding ' level. ' to all the bank var info.
in radiant theres 3 triggers. 1 trig_use & 2 trig_damage. give the 2 dmg ones the same targetname & then give each 1 of the 2 their own script_noteworthy kvp i.e
script_noteworthy
melee
&
script_noteworthy
pistol
these are what i called my trig anyway. and if u do use this damage trig approach then dont forget to check the boxes on the trigger entity window.
fior melee check all boxes apart from melee & for pistol all boxes apart from pistol.

bank()
{
    trig = getEnt("bank_trig", "targetname");
    trig setHintString("Press X to initiate");
    trig setCursorHint("HINT_NOICON");
   
    trig waittill ("trigger", player);
    trig setHintString("'Shoot' to [deposit 100], OR 'Melee' to [withdraw 100]");
   
    bank_trigs = getEntArray("bank_trigs", "targetname");
    for(i = 0; i < bank_trigs.size; i++)
    {
        bank_trigs
thread bank_sys();
   }
}

bank_sys()
{
   trig = getEnt("bank_trig", "targetname");
   bank = 0;
       
   for(;; )
   {        
       self waittill("trigger", player);
   
       if(bank < 400)
       {
           
           if (self.script_noteworthy == "pistol") // deposit
           {
               if(player.score >= 100)
               {
                   player maps\_zombiemode_score::minus_to_player_score( 100 );
                   bank = bank + 100;
                   iPrintLnBold("100 deposited");
               }
                   
               else
               {
                   iPrintLnBold("earn some mulla before trying to deposit fool!");
               }
           }
                       
           else if (self.script_noteworthy == "melee") // withdraw
           {
               if(bank >= 100)
               {
                   player maps\_zombiemode_score::add_to_player_score( 100 );
                   bank = bank - 100;
                   iPrintLnBold("100 withdrawn");
               }
               
               else
               {
                   iPrintLnBold("You aint got enough in the bank sonny!");
               }
           }
       }
       
       else
       {
           iPrintLnBold("Cant deposit anymore you rich fuck");
       }
       
   wait 0.5;
   }    
}
Last Edit: January 03, 2021, 12:23:49 pm by Phil168912

 
Loading ...