Raised This Month: $ Target: $400
 0% 

Variables between functions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kazalu
Senior Member
Join Date: Dec 2013
Location: Romania
Old 12-24-2014 , 10:42   Variables between functions
Reply With Quote #1

HTML Code:
public ctwin()
{
	CTrounds++;
	//return CTrounds;
}

public twin()
{
	Trounds++;
	//return Trounds;
}

public cmdScore( id )
{
	CTrounds = ctwin();
	Trounds = twin();
}
How can I get the return value of those functions, without modifying the variables in the process?

I mean, if I try to get Trounds in the cmdScore function, it will also add 1 to the variable value.
Kazalu is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 12-24-2014 , 10:52   Re: Variables between functions
Reply With Quote #2

If they are global variables, then just access them directly
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Kazalu
Senior Member
Join Date: Dec 2013
Location: Romania
Old 12-24-2014 , 11:00   Re: Variables between functions
Reply With Quote #3

Will they keep their values?
Like, if it was modified in a function, will it be modified in all the functions?

Last edited by Kazalu; 12-24-2014 at 11:02.
Kazalu is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 12-24-2014 , 11:08   Re: Variables between functions
Reply With Quote #4

There is only 1 copy of a global variable, so it will always return the same value regardless of which function you access it in. The same is true if you change the value of it in 1 function, all subsequent checks of the variable will return the new value
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Kazalu
Senior Member
Join Date: Dec 2013
Location: Romania
Old 12-24-2014 , 11:11   Re: Variables between functions
Reply With Quote #5

Thank you very much, sir!
Kazalu 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 15:19.


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