Sign in to follow this  
Followers 0
Vindicator209

Apply Variable from Include

8 posts in this topic

Ehh, My attempt at making a switch UDF, however, it can't tell the script that its up (or down), I'm guessing the UDF doesnt apply its own variables to the script?

All help appreciated =P

UDF:

Func _SwitchButton($swFolder,$swLeft,$swTop,$swWidth,$swHeight,$swDefault)

If $swDefault = 0 Then

$SwitchUp = GUICtrlCreatePic($swFolder & "\Up.bmp",$swLeft,$swTop,$swWidth,$swHeight)

ElseIf $swDefault = 1

$SwitchDown = GUICtrlCreatePic($swFolder & "\Down.bmp",$swLeft,$swTop,$swWidth,$swHeight)

EndIf

While 1

$msg = GUIGetMsg()

If $msg = $SwitchUp Then

GUICtrlDelete($SwitchUp)

$SwitchDown = GUICtrlCreatePic($swFolder & "\Down.bmp",$swLeft,$swTop,$swWidth,$swHeight)

EndIf

If $msg = $SwitchDown Then

GUICtrlDelete($SwitchDown)

$SwitchUp = GUICtrlCreatePic($swFolder & "\Up.bmp",$swLeft,$swTop,$swWidth,$swHeight)

EndIf

WEnd

EndFunc

My Test Script:

#include <Switches.au3>

#include <GuiConstants.au3>

GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Button_1 = _SwitchButton("Switch\ButtonSwitch", 10, 10, 140, 40,0)

GuiSetState()

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case Else

;;;

EndSelect

WEnd

Exit


[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Share this post


Link to post
Share on other sites



..Nope?


[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Share this post


Link to post
Share on other sites

..Nope?

I don't get it... :rolleyes:

Which variable are you talking about? The $swDefault variable tells the function up or down. The variables in the function are all Local, are you looking for a Global flag of some kind...?

:rambo:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Are you looking for #include "Switches.au3", I don't really understand what your question is.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

My Bad....

Ok, there are two variables I need, $SwitchUp and $SwitchDown, I put it in a while loop like a GUI, so it would act just like it would in the main script, but when testing it, the script says it doesn't exist XD

Scratch that, I just realized you can't make a control object on the main script from the include... so how do I work around this?

Edited by MethodZero

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Ok, there are two variables I need, $SwitchUp and $SwitchDown, I put it in a while loop like a GUI, so it would act just like it would in the main script, but when testing it, the script says it doesn't exist XD

Scratch that, I just realized you can't make a control object on the main script from the include... so how do I work around this?

$SwitchUp and $SwitchDown are Local unless you declared them Global somewhere else. They should work fine inside the Func, but won't be available outside it.

I think you've gone down a bad road putting your GUI loop inside the function, it can work, but is unnecessarily complicated and hard to maintain. Why bother with putting that in a UDF, and then having another GUI loop in the main script?

:rolleyes:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I agree with the penguin. Keep your gui in your program, but you should know how to declare a $var as global.

Share this post


Link to post
Share on other sites

yep, thanks!

I'll see what I can do >.>

Perhaps not much....


[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

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