PDA

View Full Version : how to call a value from another function?



xulikav
23rd July 2016, 11:17
how to call a value from another function?

for exmple i have test()
and i wanna call from it a value 'slot' for example is it possible?

IzNoGoD
23rd July 2016, 11:39
Not sure what you mean with your question. Here's a few examples:

foo()
{
a = bar();
iprintlnbold(a);
}

bar()
{
return "hello world";
}




foo()
{
iprintlnbold(bar());
}

bar()
{
return "hello world";
}



foo()
{
a = bar("world");
iprintlnbold(a);
}
bar(asdf)
{
return "hello " + asdf;
}




foo()
{
iprintlnbold(bar("hello", "world"));
}

bar(asdf, jkl)
{
return asdf + " " + jkl;
}



All these functions result in an iprintlnbold("hello world");

serthy
23rd July 2016, 11:43
how to call a value from another function?

for exmple i have test()
and i wanna call from it a value 'slot' for example is it possible?

test() call slot; (https://killtube.org/showthread.php?1740-READ-BEFORE-POSTING-Guide-on-asking-for-help)


or did you mean:

test()
{
// self is whatever the function called, for example player
if( isDefined( self ) )
{ /* do something */ }
}

player test();

xulikav
23rd July 2016, 11:49
i wanna call slot not the function the slot inside the function
Callback_PlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime)

like if (swepon ==slot)

do some shit

test()
{
self endon("disconnect");
self notify("start_sprinting");

sprint_weap="iwx_sprint_mp";
slot="";

{

IzNoGoD
23rd July 2016, 11:54
i still have no idea what you're trying to do. Explain better.

Use code tags.

Learn how to report on forums

Learn some english.

xulikav
23rd July 2016, 11:58
do you see the slot=""; inside the test funtion i wanna call it in another function

Paho
23rd July 2016, 13:19
slot="";

This visible within a given function
Use level or self or return;
return slot;

test()
{
//... use if()
slot="kot";
//... use if()
slot="pog";
//... use if()
slot="";
//...
return slot;
}

CodeCallback_PlayerCommand(args)
{
self endon("disconnect");
//...
if(args[0]=="test")
{
iprintlnbold(test());//output: kot |or| pog |or| "" - using if()
return;
}
//...
}

xulikav
23rd July 2016, 13:44
i dont mean this
i mean this

CodeCallback_PlayerCommand(args)
{
self endon("disconnect");

bingband=slot; /// how to call this slot from another function
}


test()

{
slot=3;/// i want to call the 3 to the other function how ?
}

Paho
23rd July 2016, 13:49
CodeCallback_PlayerCommand(args)
{
self endon("disconnect");
bingband=test();
}
test()
{
slot=3;
return slot;
}

xulikav
23rd July 2016, 14:09
test()
{
bosswp(slot)=3; // i want the 3 go to the bosswp function how to write that? is my writing correct?
return slot;
}




bosswp(slot)
{
slotboss=slot;
return slot;
}

Paho
23rd July 2016, 14:12
AHahAhahHaha

maxdamage99
23rd July 2016, 14:12
Omg, dude your very very stupid...


your_stupid_function()
{
/* shit code */
/*...*/
return test();
}
test()
{
slot=3;
return slot;
}

Paho
23rd July 2016, 14:19
CodeCallback_PlayerCommand(args)
{
self endon("disconnect");
bingband=test();
}
test()
{
slot=3;
return slot;
}
I'm tested it's working

xulikav
23rd July 2016, 14:21
thats not what i mean
test()=3 ; is it porssible

maxdamage99
23rd July 2016, 14:23
WHHHHAAAAAAAAAAAAAAAAAAT??????????????:DDDDDDDDDDD DDDDDDD
DUDE,MAYBE:


your_function()
/*codeee*/
/*....*/
//argument - is = 3 or someone..
test(argument);

test(a) //a = argumet
{
/* EXAMPLE: */
iprintlnbold(a); //print center 3
iprintlnbold(15/int(a)); //print center 5
players=getentarray("player","classname");
iprintlnbold(players[int(a)].name); //print center client name by clientid = 3
}

xulikav
23rd July 2016, 14:28
what im trying to do is i want to remove this from dropping iwx_sprint_mp
and instead of that i want to drop the stored value that is stored in the sprint function

dropWeapon()
{
current = self getcurrentweapon();
if(current != "none")
{
weapon1 = self getweaponslotweapon("primary");
weapon2 = self getweaponslotweapon("primaryb");

if(current == weapon1)
currentslot = "primary";
else
{
assert(current == weapon2);
currentslot = "primaryb";
}

clipsize = self getweaponslotclipammo(currentslot);
reservesize = self getweaponslotammo(currentslot);

if(clipsize || reservesize)
self dropItem(current);
}
}



Sprint()
{
self endon("disconnect");
self notify("start_sprinting");

sprint_weap="iwx_sprint_mp";
slot="";
if(self getcurrentweapon()==self getweaponslotweapon("primary"))
slot="primary";
else
slot="primaryb";
self.sweapon=self getcurrentweapon();

if(self.sweapon==sprint_weap || self.sweapon=="none")
return;

Paho
23rd July 2016, 14:28
thats not what i mean
test()=3 ; is it porssible


CodeCallback_PlayerCommand(args)
{
self endon("disconnect");
bingband=test();
}
test()
{
slot=3;
return slot;
}


This visible within a given function
Use level or self or return;
return slot;

test()
{
//... use if()
slot="kot";
//... use if()
slot="pog";
//... use if()
slot="";
//...
return slot;
}

CodeCallback_PlayerCommand(args)
{
self endon("disconnect");
//...
if(args[0]=="test")
{
iprintlnbold(test());//output: kot |or| pog |or| "" - using if()
return;
}
//...
}
test()
{
slot="kot";
return slot;
}
if(args[0]=="test")
{
iprintlnbold(test());//output: kot
return;
}
I'm tested it's working

xulikav
23rd July 2016, 14:33
what im trying to do is i want to remove this from dropping iwx_sprint_mp
and instead of that i want to drop the stored value that is stored in the sprint function

dropWeapon()
{
current = self getcurrentweapon();
if(current != "none")
{
weapon1 = self getweaponslotweapon("primary");
weapon2 = self getweaponslotweapon("primaryb");

if(current == weapon1)
currentslot = "primary";
else
{
assert(current == weapon2);
currentslot = "primaryb";
}

clipsize = self getweaponslotclipammo(currentslot);
reservesize = self getweaponslotammo(currentslot);

if(clipsize || reservesize)
self dropItem(current);
}
}



Sprint()
{
self endon("disconnect");
self notify("start_sprinting");

sprint_weap="iwx_sprint_mp";
slot="";
if(self getcurrentweapon()==self getweaponslotweapon("primary"))
slot="primary";
else
slot="primaryb";
self.sweapon=self getcurrentweapon();

if(self.sweapon==sprint_weap || self.sweapon=="none")
return;

maxdamage99
23rd July 2016, 14:34
No drop your sprint weapon:


dropWeapon()
{
current = self getcurrentweapon();
if(current=="iwx_sprint_mp")
return;
if(current != "none")
{
weapon1 = self getweaponslotweapon("primary");
weapon2 = self getweaponslotweapon("primaryb");

if(current == weapon1)
currentslot = "primary";
else
{
assert(current == weapon2);
currentslot = "primaryb";
}

clipsize = self getweaponslotclipammo(currentslot);
reservesize = self getweaponslotammo(currentslot);

if(clipsize || reservesize)
self dropItem(current);
}
}

xulikav
23rd July 2016, 14:41
in the sprint function the real wepon stored in slot so i wanted like if current=="iwx_sprint_mp"
current==slot that stored in sprint how to call that?

maxdamage99
23rd July 2016, 14:43
I no understand your fucking stupid ENGLISH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Please read TUTORIALS, C,C#,C++, you dont have PROGRAMM BASE!!!

xulikav
23rd July 2016, 14:50
if(current=="iwx_sprint_mp")

current=slot; // the slot from the sprint function

Sprint()
{
self endon("disconnect");
self notify("start_sprinting");

sprint_weap="iwx_sprint_mp";
slot="";
if(self getcurrentweapon()==self getweaponslotweapon("primary"))
slot="primary";
else
slot="primaryb";
self.sweapon=self getcurrentweapon();

if(self.sweapon==sprint_weap || self.sweapon=="none")
return;

IzNoGoD
23rd July 2016, 14:53
i still have no idea what you're trying to do. Explain better.

Use code tags.

Learn how to report on forums

Learn some english.


Still valid reply.

Paho
23rd July 2016, 14:53
if(current=="iwx_sprint_mp")
current=Sprint();
Sprint()
{
self endon("disconnect");
self notify("start_sprinting");
sprint_weap="iwx_sprint_mp";
slot="";
if(self getcurrentweapon()==self getweaponslotweapon("primary"))
slot="primary";
else
slot="primaryb";
self.sweapon=self getcurrentweapon();
return slot;
}

xulikav
23rd July 2016, 14:54
Sprint()
{
self endon("disconnect");
self notify("start_sprinting");

sprint_weap="iwx_sprint_mp";
slot="";
if(self getcurrentweapon()==self getweaponslotweapon("primary"))
slot="primary";
else
slot="primaryb";
self.sweapon=self getcurrentweapon();

if(self.sweapon==sprint_weap || self.sweapon=="none")
return;

self.sammo1=self getWeaponSlotAmmo(slot);
self.sammo2=self getWeaponSlotClipAmmo(slot);
self.is_Sprinting = true;
self setWeaponSlotWeapon(slot, sprint_weap);

sprint_ammo = int( (self.sprint_stamina / level.sprint_time) * 100 );

self setWeaponSlotAmmo(slot, sprint_ammo);
self switchToWeapon(sprint_weap);
wait 0.25;
maxwidth = 100;

while ( isAlive(self) && self useButtonPressed() && self.sprint_stamina > 0 && self getcurrentweapon()==sprint_weap)
{
wait 0.1;

if(!isMoving(self))
break;

self.sprint_stamina -= 25;

if(self.sprint_stamina < 0)
self.sprint_stamina = 0;

sprint_ammo = int( (self.sprint_stamina / level.sprint_time) * 100 );

self setWeaponSlotAmmo(slot, sprint_ammo);
}

if ( isAlive(self) && self.sweapon!="none" && (self getcurrentweapon()==sprint_weap || self getcurrentweapon()=="none"))
{
self setWeaponSlotWeapon(slot,self.sweapon);
self setWeaponSlotAmmo(slot,self.sammo1);
self setWeaponSlotClipAmmo(slot,self.sammo2);
self switchToWeapon(self.sweapon);
self.is_Sprinting = false;
}

if ( isAlive(self) && self.sweapon!="none" && self getcurrentweapon()!=sprint_weap && self getcurrentweapon()!="none")
{
self setWeaponSlotWeapon(slot,self.sweapon);
self setWeaponSlotAmmo(slot,self.sammo1);
self setWeaponSlotClipAmmo(slot,self.sammo2);
self.is_Sprinting = false;
}
}

xulikav
23rd July 2016, 14:58
thats the sprint function

Paho
23rd July 2016, 15:02
what's problems?

IzNoGoD
23rd July 2016, 15:21
Stop posting code without code tags.

xulikav
23rd July 2016, 15:26
if(current=="iwx_sprint_mp")

current=slot;/// how to bring the slot value from inside the function sprint to add it to the dropwepon function

Paho
23rd July 2016, 15:32
use continue;
inside the function to the following condition