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;
}
}