Jump to content

2 Functions at the same time?


 Share

Recommended Posts

Hey, now I have another problem; I finally after hours struggle got the alarm/timer thing working, worst problem was to set certain time from Combobox but now it works.

However, there is a problem that makes the timer useless, if I can't run two functions at the same.

The thing that alarm does is that it counts to like 30 sec, 1 min, 2min etc. and after that time is up, the program will close. That script was easy to make and works fine BUT my program won't do anything else it is supposed to be while I activate the alarm. I also took a look from this: https://www.autoitscript.com/wiki/Interrupting_a_running_function but I did not quite understood how I set it into my script, so the thing I have is running alarm and during the alarm runs, my program should be available to do Functions like Send("Hello notepad") as long as the timer runs. Now the timer only runs, but doesn't send letters to my notepad.

Here is a customized function from my last one (in another topic)

Func TimerRun()
      If GUICtrlRead($checkboxRunTimer) = 1 And $AllowTimer = 1 Then
         ;Global $RunningTimer
         ;$RunningTimer = TimerInit() <-- Comment because it didnt work but might be the solution for this problem
         Do
            $Timer+=1
            ToolTip($Timer)
         Until $Timer > $MaximumTime
         ;This is comment because it didn't work --> Until TimerDiff($RunningTimer) > $MaximumTime
         If $AllowTimer = 1 Then
            $AllowTimer = 0
            $Timer = 0
            ToolTip("Time is up!")
            Sleep(2000)
            Exit
         EndIf
      EndIf
EndFunc

There is the timer script, now I need to run this Function at the same as the time goes by:

Func WriteNotepad()
    Send("Hello notepad!")
    Sleep(1000)
EndFunc

And this Function is inside of While 1 loop but I guess I don't need to post that one here.

So how can I actually use that OnEvent thing in my Function/Script, because that tutorial was hard to understand or either I am too tired after 10 hours of programming.. >_<

Argh, sometimes coding is annoying, but thanks in advance!

Edited by Timppa
Forgot " from Send
Link to comment
Share on other sites

Hmm, there are problems:

I don't only run Func WriteNotepad(), I also run Func Randomize() which randomizes numbers and does action based on the chosen number and many more Funcs, the main thing is that Timer always is on, but other functions might change.

Other problem: I don't really understand that script because it is not commented, last game project I programmed got abandoned because of too much copy paste script withoute ven knowing how to modify and which command does what.

Local $tmp1 = @TempDir & "\tempexec1.tmp"
    Local $tmp2 = @TempDir & "\tempexec2.tmp"
    Local $hwnd = FileOpen($tmp1, 26)

So it makes a file to my Temp folder? What is $hwnd and why number 26 after $tmp1 o_o

That really bugs me but thanks for help! :)

Link to comment
Share on other sites

  • Developers

 

What is $hwnd and why number 26 after $tmp1 o_o

Ever thought of looking at the helpfile to figure stuff out and learn? ;)

 

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

Ever thought of looking at the helpfile to figure stuff out and learn? ;)

 

Thats what I have done the whole day. As I said before, I took a look at the interrupting a running function article but it didn't made me sure how to use it, since I don't just use two functions but many of them, and certain function must be running the whole time.

 

EDIT: And yes, $hwnd is a variable but what does it stands for? Horizontal Whale's Naughty Dance?

Edited by Timppa
Link to comment
Share on other sites

  • Developers

It was specifically aimed at the quoted question, which is easily answered by the helpfile.

Jos

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

It was specifically aimed at the quoted question, which is easily answered by the helpfile.

Jos

Yes, $hwnd opens "\tempexec1.tmp" file if I understood correctly, now the problem is that what does 26 mean?

In helpfile it is explained like this: 

FileOpen($sFilePath, $FO_READ)

Then there is this:

[optional] Mode to open the file in.
Can be a combination of the following:
    $FO_READ (0) = Read mode (default)
    $FO_APPEND (1) = Write mode (append to end of file)
    $FO_OVERWRITE (2) = Write mode (erase previous contents)
    $FO_CREATEPATH (8) = Create directory structure if it doesn't exist (See Remarks).
    $FO_BINARY (16) = Force binary mode (See Remarks).
    $FO_UNICODE or $FO_UTF16_LE (32) = Use Unicode UTF16 Little Endian reading and writing mode.
 

But there is nowhere said what does a number do? What means mode 26.

If someone clever commented that script which was made by Chimp, I'd probably understand a little more.

And if someone said if it's available to do with several different functions and with the timer function, as I've stated millions time before.

Link to comment
Share on other sites

  • Developers

Clue: 26=16+8+2   ;)

.. and a filehandle is returned by FileOpen() which then needs to be used for reading/writing and closing the file.

Jos

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

Clue: 26=16+8+2   ;)

.. and a filehandle is returned by FileOpen() which then needs to be used for reading/writing and closing the file.

Jos

Thanks! Now you actually answered to my question. However I read the whole FileOpen from helpfile and unless I am blind, I did not see anywhere that you can just make like FileOpen($variable, number combination) because there was this in the second script 

FileOpen($sFilePath, $FO_READ + $FO_OVERWRITE)

So that would make me learn to use + after I want to add more modes into it. Maybe update the helpfile then?

And yet I don't know if I can use multiple functions because if I used like 100 functions at different time BUT with Timer all the time, I should create 100 variables that are like $code1, $code2, .... $code100 ? and then _ExecuteScript($code1,...$code100) and make 100 different temporary files in Temp folder?

And no, I'm not lazy programmer, just new to this language. That is why it's hard for me to understand.

In 3 weeks of practicing AutoIt I've made 1400 lines of script without help, but now I challenge something that I haven't done/experienced before.

Link to comment
Share on other sites

  • Developers

Would think this wording is explicit enough:


[optional] Mode to open the file in.
Can be a combination of the following:
 

.. agree?

Jos

 

Edited by Jos

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

Would think this wording is explicit enough:

.. agree?

Jos

 

Yes, as combination I understood this AS THE EXAMPLE SHOWED like this:

 

FileOpen($sFilePath, $FO_READ + $FO_OVERWRITE)

That is sir, a combination of different modes, not different numbers. Where is it defined that it can be a number as well?

[optional] Mode to open the file in.
Can be a combination of the following:
    $FO_READ (0) = Read mode (default)
    $FO_APPEND (1) = Write mode (append to end of file)
    $FO_OVERWRITE (2) = Write mode (erase previous contents)
    $FO_CREATEPATH (8) = Create directory structure if it doesn't exist (See Remarks).
    $FO_BINARY (16) = Force binary mode (See Remarks).
    $FO_UNICODE or $FO_UTF16_LE (32) = Use Unicode UTF16 Little Endian reading and writing mode.
    $FO_UTF16_BE (64) = Use Unicode UTF16 Big Endian reading and writing mode.
    $FO_UTF8 (128) = Use Unicode UTF8 (with BOM) reading and writing mode.
    $FO_UTF8_NOBOM (256) = Use Unicode UTF8 (without BOM) reading and writing mode.
    $FO_ANSI (512) = Use ANSI reading and writing mode.
    $FO_UTF16_LE_NOBOM (1024) = Use Unicode UTF16 Little Endian (without BOM) reading and writing mode.
    $FO_UTF16_BE_NOBOM (2048) = Use Unicode UTF16 Big Endian (without BOM) reading and writing mode.
    $FO_FULLFILE_DETECT (16384) = When opening for reading and no BOM is present, use the entire file to determine if it is UTF8 or UTF16. If this is not used then only the initial part of the file (up to 64KB) is checked for performance reasons.
The folder path must already exist (except using $FO_CREATEPATH mode - See Remarks).
 

 

Not in this, it never says a COMBINATION OF NUMBERS, it says combination of the following. Please update the helpfile since it is clearly misleading, or either add a third example that explains the usage of combinated numbers.

Thank you, and again, you never explained me if I can use several functions at the same...

Link to comment
Share on other sites

Each one of those variables is assigned a numeric value, the number in the parentheses. You can use either the variables, or the number it equals, or any combination of the two. The variables are there so you don't end up with the problem you have, someone used the numbers and you don't know what they stand for. If they had uses the variables instead of their values, then you could have easily seen that they used Binary mode, CreatePath, and OverWrite mode.

That's why "magic numbers" are frowned upon and named variables are used in place of "magic numbers".

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Each one of those variables is assigned a numeric value, the number in the parentheses. You can use either the variables, or the number it equals, or any combination of the two. The variables are there so you don't end up with the problem you have, someone used the numbers and you don't know what they stand for. If they had uses the variables instead of their values, then you could have easily seen that they used Binary mode, CreatePath, and OverWrite mode.

That's why "magic numbers" are frowned upon and named variables are used in place of "magic numbers".

 

Yeah, now I understand that finally and that makes me relieved. I don't like it that someone is being rude to me because I don't know this language well. I know Java, C#, C++, and GML but not AutoIt that well. Thanks for helping me! And that could be written in helpfile to prevent noobs like me :D

But now for the original question, can I still run multiple funcs and have timer always on? I guess I'll get a ban soon for repeating this same question but I haven't found a solution. Can I use some kind of array if I have multiple functions running?

Link to comment
Share on other sites

  • Developers

I am trying to understand what makes you so defensive.
Is it my short answers that gives you a partial answer in a effort to make you think for yourself and learn while having to do some efforts?

not sure whom you are considering rude here either?
Anyway: Stop blaming the Helpfile for not being explicit enough. ;)

As to your question: That question was asked many time and the simple plain answer is: NO!
You can interrupt a function to run something else and then return, but that is it.

Jos
 

 

Edited by Jos

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

I am trying to understand what makes you so defensive.
Is it my short answers that gives you a partial answer in a effort to make you think for yourself and learn while having to do some efforts?

not sure whom you are considering rude here either?
Anyway: Stop blaming the Helpfile for not being explicit enough. ;)

As to your question: That question was asked many time and the simple plain answer is: NO!
You can interrupt a function to run something else and then return, but that is it.

Jos
 

 

Thank you, finally an answer that could've been answered in 1 post and with 2 letters.

Stop blaming the helpfile? What.. So you tell me to read helpfile and then quit blaming it because it's not explicit enough?

Never heard as silly as that before...

But this case is closed now, gotta find a solution to this by myself. Or change language because by far DEVELOPERS have been more friendly towards me in other forums if I haven't known something.

Link to comment
Share on other sites

  • Developers

I love your tone in that last post and your are out on your own again as far as I am concerned.
Happy coding.

Jos

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

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...