Jump to content

Variable to function


Recommended Posts

Is it possible to get a variable to go to a function.

i.e.

$Name = "Animals"

$Next = "Art()"

Common()

Func Common()

$msg = MsgBox(4099, "Please Choose", "Install files for " & $Name & "?", 8)

If $msg = 7 then $Next

If $msg = 2 then exit

RunWait ("OpenAll+.exe Letters\" & $Name & "\")

$Next

EndFunc

Func Art()

$Name = "Art"

$Next = "Bon()"

Common()

EndFunc

Edited by Mr.Furious
Link to comment
Share on other sites

You mean can you use a variable that you use in a function outside it?

And yes can do something like this

$Next = "Bon()"

With out the quotation marks and only if the function returns something. eg.

$Next = Bon()

Msgbox(0,"Co-ordinates", "X: " & $Next[0] & " Y: " & $Next [1])
Func Bon()
   $Pos = MouseGetPos()
   Return $Pos
EndFunc
Edited by Burrup

qq

Link to comment
Share on other sites

Actually I want to jump to another area in the script to get the next set of variables and I will need to do this many times.

There doesn't seem to be goto in autoit so I was trying to use functions to have areas to have the script goto.

so basically I was trying to jump out of the function to another function to get the next set of variables.

I can't get it to work as expected however.

Link to comment
Share on other sites

Just call the function when you need it. Or in the function get it to read the variables from another one and have lots of functions. If you dont put Global $Var at in your script you wont be able to use the variables created by a function in another function.

qq

Link to comment
Share on other sites

I am starting to feel real stupid here cause I cant seem to get it to work.

Here is a sample of what I got.

Global $Name
Global $Next

Animals()

Func Common()
$msg = MsgBox(4099, "Please Choose", "Install All Letters For " & $Name & "?" & @CR & @CR & "Automatic installation if no response within 8 seconds", 8)
    If $msg = 7 then Return $Next
    If $msg = 2 then exit
    RunWait ("OpenAll+.exe Letters\" & $Name & "\")
    Return $Next
EndFunc

Func Animals()
    $Name = "Animals"
    $Next = Art()
    Common()
EndFunc

Func Art()
    $Name = "Art"
    $Next = Bon()
    Common()
EndFunc

Func Bon()
    $Name = "Bon Appetit"
    $Next = Done()
    Common()
EndFunc

Func Done()
    $Name = 0
    $Next = 0
    Exit
EndFunc
Edited by Mr.Furious
Link to comment
Share on other sites

I think I understand what you want.

$msg = MsgBox(4099, "Please Choose", "Install All Letters For Animals?" & @CR & @CR & "Automatic installation if no response within 8 seconds", 8)
If $msg = 6 then 
   RunWait ("OpenAll+.exe Letters\Animals\")
ElseIf  $msg = 2 Then
   Exit
EndIf

$msg = MsgBox(4099, "Please Choose", "Install All Letters For Art?" & @CR & @CR & "Automatic installation if no response within 8 seconds", 8)
If $msg = 6 then 
   RunWait ("OpenAll+.exe Letters\Art\")
ElseIf  $msg = 2 Then
   Exit
EndIf

$msg = MsgBox(4099, "Please Choose", "Install All Letters For Bon Appetit?" & @CR & @CR & "Automatic installation if no response within 8 seconds", 8)
If $msg = 6 then 
   RunWait ("OpenAll+.exe Letters\Bon Appetit\")
ElseIf  $msg = 2 Then
   Exit
EndIf
Edited by Burrup

qq

Link to comment
Share on other sites

  • Developers

I am starting to feel real stupid here cause I cant seem to get it to work.

Here is a sample of what I got.

<{POST_SNAPBACK}>

The issue is that the script follows this path:

Call Animals()

Animals calls Art()

Art calls Bon()

Bon calls Done()

Done does Exit !

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

This is how I started but seemed bloated and messy when your talking about 75 plus items. I got carried away trying to make it streamlined.

I think I understand what you want.

$msg = MsgBox(4099, "Please Choose", "Install All Letters For Animals?" & @CR & @CR & "Automatic installation if no response within 8 seconds", 8)
If $msg = 6 then 
   RunWait ("OpenAll+.exe Letters\Animals\")
ElseIf  $msg = 2 Then
   Exit
EndIf

$msg = MsgBox(4099, "Please Choose", "Install All Letters For Art?" & @CR & @CR & "Automatic installation if no response within 8 seconds", 8)
If $msg = 6 then 
   RunWait ("OpenAll+.exe Letters\Art\")
ElseIf  $msg = 2 Then
   Exit
EndIf

$msg = MsgBox(4099, "Please Choose", "Install All Letters For Bon Appetit?" & @CR & @CR & "Automatic installation if no response within 8 seconds", 8)
If $msg = 6 then 
   RunWait ("OpenAll+.exe Letters\Bon Appetit\")
ElseIf  $msg = 2 Then
   Exit
EndIf

<{POST_SNAPBACK}>

Link to comment
Share on other sites

Yah that's exactly what happens damn thing. :)

Bounces from next to next and doesn't do my common task.

Is this just not going to work out and I should use the bloated way?

The issue is that the script follows this path:

Call Animals()

Animals calls Art()

Art calls Bon()

Bon calls Done()

Done does Exit !

<{POST_SNAPBACK}>

Link to comment
Share on other sites

I think i know what he wants, he wants to store a variable name then call that. To do it use code like this:

$Call = "Function"
Call ( $Call )

Func Function()
   MsgBox ( 0, "Example", "I called $Call which enabled this box to show" & @CRLF & "$Call=" & $Call )
EndFunc
Edited by Xenogis

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Link to comment
Share on other sites

Call seems to work the same as return and still produces the same strange run as JdeB mentioned :)

Sure be easier if could have a section

:Art

$name="art"

$next="bon"

Common()

and just get the function to goto the art section get the varibles run the msgbox then move on to the next section and so on and so on

Edited by Mr.Furious
Link to comment
Share on other sites

What about this using my suggestion?

Global $Name
Global $Next

Animals()

Func Common()
$msg = MsgBox(4099, "Please Choose", "Install All Letters For " & $Name & "?" & @CR & @CR & "Automatic installation if no response within 8 seconds", 8)
    If $msg = 7 then Call ( $Next )
    If $msg = 2 then exit
    RunWait ("OpenAll+.exe Letters\" & $Name & "\")
    Call ( $Next )
EndFunc

Func Animals()
    $Name = "Animals"
    $Next = "Art"
    Common()
EndFunc

Func Art()
    $Name = "Art"
    $Next = "Bon"
    Common()
EndFunc

Func Bon()
    $Name = "Bon Appetit"
    $Next = "Done"
    Common()
EndFunc

Func Done()
    $Name = 0
    $Next = 0
    Exit
EndFunc

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

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