Jump to content

Can A Variable Set Another Variable?


Recommended Posts

Ok... I Am Working Of A System And I Want The Func To Be Able To Set A Return...

Heres What I'm Talking About...

Func _Add ($Add_1 , $Add_2 , $Return)
$Return = $Add_1 + $Add_2
EndFunc

;Example

_Add (5 , 5 , $Add_Equal ) ; I Want $Add_Equal To Be The Return Value.... Without Haveing To Set It In The Top
MsgBox (0, "Test", $Add_Equal,0)

Can Anyone Help Me Please! :/

Please Give Me An Example.. If You Can Help Me... :)

Edited by John2006

Latest Projects :- New & Improved TCP Chat

Link to comment
Share on other sites

HI,

Func _Add($Add_1, $Add_2)
    Return $Add_1 + $Add_1
EndFunc  ;==>_Add

;Example

; I Want $Add_Equal To Be The Return Value.... Without Haveing To Set It In The Top
MsgBox(0, "Test", _Add(5, 5), 0)

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

This must be a typo

$Return = $Add_1 + $Add_1

... $1 + $1? you mean $1 + $2 right?

If you are going to hardcode the "$Add_Equal" in

"_Add (5 , 5 , $Add_Equal )"
then why not just hardcode the return:

Func _Add ($Add_1 , $Add_2 )
Return $Add_1 + $Add_2
EndFunc
$Add_Equal = _Add (5 , 15 )
MsgBox (0, "Test", $Add_Equal,0)
Link to comment
Share on other sites

@John2006: there is an Edit button.

But Anyways if you could tell what you mean by:

$Return = A Different Var... Without Edited The Func?

If you mean that You want to use the $Return variable outside of the function and inside of the function it would be something like this:

Global $Return
_Add(1,1) ;This should equal 2
MsgBox(0,'',$return) ;should be 2
$Return = $Return + 7
MsgBox(0,'',$return) ;2+7 = 9 therefore the answer should be nine
_Add(3,4); 3+4 = 7 so the answer would be 7
MsgBox(0,'',$return)




Func _Add($var_1,$var_2) ;Adds var 1 and Var 2 into the $return var
$Return = $var_1 + $var_2
Endfunc

Notice this way the var $return doesn't have to be just inside the fucntion, nor do you have to pass it. See the globals work so that functions read the var the same way the script outside of functions do. The code you posted has local vars thats why you must use Return() to return that local var. Hope that helps!

[center][/center]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...