Sign in to follow this  
Followers 0
Mr.Furious

Variable to function

14 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


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

Share this post


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


[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


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

<{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 !


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

What you want is COROUTINE, isn't it ?

ps: Why are there only the 3 first volumes from D. Knuth "The Art of Computer Programming" ? :)


Gestion des congés, RTT, vacances scolaires, autres absences sur Pocket PC : CongésRFV

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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]

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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

Share this post


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

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Wooo hooo you got it to work!!

Thanks, thanks, thanks!!

Problem was when I was using your suggestoin I had the brackets in there:

$Next = "Art()"

Instead of $Next = "Art"

Edited by Mr.Furious

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
Sign in to follow this  
Followers 0