hello autoiters,
i want to create functions from within a for loop and give them names from items in an array.
for $s = 1 to $swfgames [0] $name = StringTrimRight($swfgames[$s], 4) $v = execute($name) Func $v() shellexecute (@scriptdir & "\gamez\flashplayer_10_sa.exe", @scriptdir & "\files\swf\" & $name) EndFunc next
when i run the above code it tell me
" "For" statement has no matching "Next" statement.:"
wtf.
the entire program im writing will pull names of a bunch of .swf (flash) games from a local folder, then create a dynamic GUI to launch them from buttons. i got that part done (i think) but i cant connect GUICtrlsetonevent to each game. full program below and the game files are attached if you'd like to try it out. look at line 55 for the correct directory to put them in.
AutoIt
#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> Global $swfgames = _FileListToArray(@scriptDir & "\files\swf\", "*", 1), $howmanygames = $swfgames[0] func main() Opt("GUICoordMode", 2) Opt("GUIOneventmode", 1) Opt("GUIResizeMode", 1) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") $size = $howmanygames * 30 ;this is the heoght of the GUI window GUICreate ("I Like Flash Gamez", 300, $size) $firstrow = $howmanygames / 2 ;this determines the size of the left column $secondrow = $firstrow + 1 ;this is the size of the right column ;~ these are the functions to create the buttons for the games ;~ this is the left column For $I = 1 To $firstrow local $x, $height1 = 30 $height1 = $height1 + 30 $name = StringTrimRight($swfgames[$I], 4) GUICtrlCreateButton ($name, 10, $height1) GUIctrlsetonevent(-1, $name) Next ;~ this is the right column For $I = $secondrow To $swfgames[0] local $y, $height2 = 30 $height2 = $height2 + 30 $name = StringTrimRight($swfgames[$I], 4) GUICtrlCreateButton ($name, 160, $height2) GUICtrlSetOnEvent(-1, $name) Next GUISetState(@sw_show) While 1 sleep (10) WEnd EndFunc for $s = 1 to $swfgames [0] $name = StringTrimRight($swfgames[$s], 4) $v = execute($name) Func $v() shellexecute (@scriptdir & "\gamez\flashplayer_10_sa.exe", @scriptdir & "\files\swf\" & $name) EndFunc next Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Case @GUI_CtrlId = $GUI_EVENT_RESTORE EndSelect EndFunc func errorcheck() local $filesdir = (@scriptdir & "\files"), $swfdir = @scriptdir & "\files\swf" Select case not FileExists($filesdir) MsgBox (48, "Whoops!", "Looks like the data directory:" & @CRLF & $filesdir & @CRLF & "doesnt exist! Read the 'readme.txt' file!") case not FileExists($swfdir) MsgBox (48, "Whoops!", "Looks like the game directory:" & @CRLF & $swfsdir & @CRLF & "doesnt exist! Make sure you have this folder and it is filled with .swf games!") case not FileExists($swfdir & "\*") MsgBox (48, "Whoops!", "Looks like the game directory:" & @CRLF & $swfsdir & @CRLF & "is empty! Make sure your .swf files are located in that folder.") case not FileExists ($files & "\flashplayer_10_sa.exe") MsgBox (48, "Whoops!", "Looks like you're missing the flash player!:" & @CRLF & $filesdir & @CRLF & "Make sure the program 'flashplayer_10_sa.exe' is in the above directory or your games won't play.") EndSelect EndFunc errorcheck() main()