Raised This Month: $ Target: $400
 0% 

Transfer variables from one function to another


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 07-06-2010 , 21:53   Transfer variables from one function to another
Reply With Quote #1

I think this question is kinda dumb and maybe its already asked somewhere.
I came across this problem many times before and because of my lack of knowledge i couldnt go over it.So I'm asking now how is it possible.
PHP Code:
public asd()
{
if(
smth == 1)
{
a++
}
public 
adf()
{
if(
== 2// line X
{
...

Of course on line X it will bring up error for undefined symbol and if i define it in adf() it will not have the same value as asd().
If i define it out of the both functions, again it will ot have the same value.

Last edited by SpeeDeeR; 07-07-2010 at 05:34.
SpeeDeeR is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 07-06-2010 , 23:01   Re: Transfer variables from one function to another
Reply With Quote #2

First of all...

PHP Code:
if(2
-->

PHP Code:
if(== 2
And same for smth = 1.

The whole code should be something like this:

PHP Code:
new a;

public 
asd()
{
    if(
smth == 1)
    {
        
a++;
    }
}

public 
adf()
{
    if(
== 2)
    {
        
// something
    


just create "a" variable, as global.
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Alucard^ is offline
Send a message via Skype™ to Alucard^
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-06-2010 , 23:09   Re: Transfer variables from one function to another
Reply With Quote #3

I'm not 100% sure what your question is but maybe this will help.

Passing a variable by-reference. You will see "Var1=4" in console.
PHP Code:
register_concmd"test" "TestFunc" );

public 
TestFuncid )
{
    
Func1();
}

public 
Func1()
{
    new 
Var1;
    
    
Func2Var1 );
    
Func2Var1 );
    
Func2Var1 );
    
Func2Var1 );
    
    
server_print"Var1=%d" Var1 );
}

public 
Func2( &TheVar )
{
    
TheVar++;

Using a global variable. You will see "Var1=4" on the first command, "Var1=8" on the second and so on, each incremented by 4.
PHP Code:
//Place this outside of all functions (below your includes or whatever)
new Var1;

register_concmd"test" "TestFunc" );

public 
TestFuncid )
{
    
Func1();
}

public 
Func1()
{
    
Func2();
    
Func2();
    
Func2();
    
Func2();
    
    
server_print"Var1=%d" Var1 );
}

public 
Func2()
{
    
Var1++;

__________________
Bugsy is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 07-07-2010 , 05:40   Re: Transfer variables from one function to another
Reply With Quote #4

The thing that I'm asking is how to pass values from a function to another.Like in my example i want to pass the value of variable 'a' in asd() to the variable 'a' in adf().I just want 'a' in asd() to be equal to 'a' in adf().
SpeeDeeR is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 07-07-2010 , 05:45   Re: Transfer variables from one function to another
Reply With Quote #5

PHP Code:
public asd()
{
new 
a
if(smth == 1)
{
a++
adf(a)
}
public 
adf(a)
{
if(
== 2// line X
{
...

__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.
Owyn is offline
Send a message via ICQ to Owyn
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 07-07-2010 , 05:59   Re: Transfer variables from one function to another
Reply With Quote #6

Thank you @Owyn.Now when that is cleared I'm asking again how to do it but this time for multiple values passed in a single function.
SpeeDeeR is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 07-07-2010 , 06:05   Re: Transfer variables from one function to another
Reply With Quote #7

PHP Code:
public asd()
{
new 
ab
if(smth == 1)
{
a++
b++
adf(a,b)
}
public 
adf(a,b)
{
if(
== 2// line X
{
...
}  
if(
== 2// line Y
{
...

</span></span>
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.
Owyn is offline
Send a message via ICQ to Owyn
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 07-07-2010 , 06:06   Re: Transfer variables from one function to another
Reply With Quote #8

omfg thank you again.That clears up eveything.
SpeeDeeR is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:10.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode