Entkalker Posted June 18, 2018 Share Posted June 18, 2018 Hello, I have a actually a script that is running in a loop until a variable gets a special number. And this script is fully working and running. Now I need Functions to repeat different tasks in between the full loop. While 1 Func Line1() Link to comment Share on other sites More sharing options...
Earthshine Posted June 18, 2018 Share Posted June 18, 2018 what functions do you need? Can we see your script? if you post it in the CODE TAGS I bet a really nice person here would probably help you write it if you spell out the requirements and show us what you've tried. example code in CODE TAGS <> My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Entkalker Posted June 18, 2018 Author Share Posted June 18, 2018 (edited) Hello, I have actually a script that is running in a loop until a variable gets a special number. And this script is fully working and running. Now I need Functions to repeat different tasks in between the full loop. In a easy way I want it this way: $variable =0 While 1 Func Line1() If $variable = 22 Then MsgBox(64, 'Finished', 'Task Finished') ExitLoop EndFunc $variable +=1 WEnd But i get always this error: What did I wrong? Edited June 18, 2018 by Entkalker Link to comment Share on other sites More sharing options...
Subz Posted June 18, 2018 Share Posted June 18, 2018 You should never create a function within a loop, you basically only had to do the following: $iVariable = 0 While 1 $iVariable +=1 If $iVariable = 22 Then ExitLoop MsgBox(64, 'Finished', 'Task Finished') Sleep(1000) ;~ Sleep 1 Second WEnd Link to comment Share on other sites More sharing options...
Earthshine Posted June 18, 2018 Share Posted June 18, 2018 why a new post? My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Entkalker Posted June 18, 2018 Author Share Posted June 18, 2018 Is there no possibility to put the function into the loop? Or can I do jumps without functions? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted June 18, 2018 Moderators Share Posted June 18, 2018 Stick to one thread, please. "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 More sharing options...
Earthshine Posted June 18, 2018 Share Posted June 18, 2018 (edited) Main() While 1 loop and look for event or values If event or value Then Func1() Elseif Func2() EndIf WEnd EndFunc Func1() Do some func1 stuff EndFunc Func2() Do some func1 stuff EndFunc you don't do it like that. you create separate functions. then you can call them as you need them Edited June 18, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Entkalker Posted June 18, 2018 Author Share Posted June 18, 2018 (edited) Ok thank you. I think I know how to do it now. Can I also do the functions above the Main() or is that not possible? Func1() Do some func1 stuff EndFunc Func2() Do some func1 stuff EndFunc Main() While 1 loop and look for event or values If event or value Then Func1() Elseif Func2() EndIf WEnd EndFunc Edited June 18, 2018 by Entkalker Link to comment Share on other sites More sharing options...
Subz Posted June 18, 2018 Share Posted June 18, 2018 As mentioned you should never create functions within a loop. The issue with your script above: You were just recreating the function over and over. It would never have finished because you never called the function You forgot to add an EndIf within your function Recommend you use Scite for testing your scripts in Scite Click Tools » Go or press F5 Here is an example of how you would create your script, although my method above does exactly the same thing. Global $g_iVariable = 0 While 1 $g_iVariable += 1 If Line1() Then ExitLoop Sleep(100) ;~ Sleep 100ms between loops WEnd Func Line1() If $g_iVariable = 22 Then MsgBox(64, 'Finished', 'Task Finished') Return 1 EndIf Return 0 EndFunc Link to comment Share on other sites More sharing options...
Entkalker Posted June 18, 2018 Author Share Posted June 18, 2018 Ok im really new with functions, so my question is what will the script do next after finishing the function? Link to comment Share on other sites More sharing options...
Earthshine Posted June 18, 2018 Share Posted June 18, 2018 (edited) function ends and passes back to your loop that called it. you loop until that variable is 22 basically. your $g_iVariable is your loop counter that keeps going up and you evaluate that value with Line1 Edited June 18, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Entkalker Posted June 18, 2018 Author Share Posted June 18, 2018 ok so i only need to put the function out of the loop and call it in the loop? And after the function ends the loop will continue after the call function line? Link to comment Share on other sites More sharing options...
Earthshine Posted June 18, 2018 Share Posted June 18, 2018 (edited) yes indeed. When Line1() returns a 1 and that exits the main loop. Edited June 18, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted June 18, 2018 Moderators Share Posted June 18, 2018 @Entkalker pretty much every question you have asked could easily be answered by trying it for yourself. You would find you get the answers a lot faster than posting and waiting for someone to respond. Earthshine 1 "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 More sharing options...
Entkalker Posted June 18, 2018 Author Share Posted June 18, 2018 So I got it and it works thank you all for your help Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now