Jump to content

Calling a variable within another function


KyleB
 Share

Recommended Posts

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"

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

Yes, that is the code - I thought you were posting the actual error you're receiving. That will help us a great deal.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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)?

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...