Jump to content
KyleB

Calling a variable within another function

Recommended Posts

KyleB

I'm creating a script to create a new user and log into ts every time, I had it working but when i started simplifying my code into functions so i could separate them while testing, It couldn't find the variable. I'm just wondering if there is a way to take that variable from the other function.

 

LaunchSEQ ()
NameGen ()
JoinSEQ ()

Func NameGen ()
Local $arr[26] = ["Alpha","Bravo","Charlie","Delta","Echo","Foxtrot","Golf","Hotel","India","Juliet","Kilo","Lima","Mike","November","Oscar","Papa","Quebec","Romeo","Sierra","Tango","Uniform","Victor","Whisky","X-Ray","Yankee","Zulu"]
   $i = Random(1, 26, 1)
   $name = $arr[$i] & "|Burns"
Send($name)
EndFunc

Func JoinSEQ ()
send("{ENTER}")
Send("^s")
Sleep(250)
Send("{TAB}")
Sleep(250)
Send("^a")
Sleep(250)
Send($name)
sleep(250)
send("{ENTER}")
EndFunc

Error is located at the bottom regarding the variable "$name"

Share this post


Link to post
Share on other sites
JLogan3o13

I don't see the error you reference, but if you need $name to be available to the entire script, the declare it at the top as Global. If this function is going to return that variable for use in a subsequent function, use Return instead (see help file for both).

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
KyleB

 

It says "Error: Variable used without being declared.", while i have declared it above it, just within another function.

   $name = $arr[$i] & "|Burns"
Send($name)
EndFunc
Sleep(250)
Send($name)
sleep(250)
send("{ENTER}")
EndFunc
Edited by KyleB

Share this post


Link to post
Share on other sites
spudw2k
On 11/11/2016 at 1:46 PM, KyleB said:

Fixed it, thanks

It's always helpful to the forum community if you share how you resolved it.   Was it the because your random function upper and lower limits were wrong (zero-indexed array...0 to 25 instead of 1 to 26)?

Share this post


Link to post
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

×