Author Topic: On Timer only allows SUB with Integer argument error?  (Read 5894 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
On Timer only allows SUB with Integer argument error?
« on: September 19, 2019, 11:25:01 pm »
Just what is this about?
Code: QB64: [Select]
  1. DIM Board(50, 30) AS INTEGER
  2. CONST TRUE = -1, FALSE = NOT TRUE
  3.  
  4. CONST MaxX = 50
  5. CONST MaxY = 30
  6. on timer(t1&,.025) AgeBoard(Board())
  7.  
  8. sub AgeBoard(B())
  9.  FOR x%% = 1 TO MaxX
  10.   FOR y%% = 1 TO MaxY
  11.    B(x%%, y%%) = FALSE
  12.  NEXT y%%, x%%
  13.  

ERROR:"Only SUB arguments of integer-type are allowed on line 7:

and yet Board is an integer type

why would it matter what type is sent to the sub by the Timer?

or is there something else going on and that is just some generic error coming up and not really telling what the true error is?
Granted after becoming radioactive I only have a half-life!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: On Timer only allows SUB with Integer argument error?
« Reply #1 on: September 19, 2019, 11:49:25 pm »
Board isn’t an integer; it’s an ARRAY of integers.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: On Timer only allows SUB with Integer argument error?
« Reply #2 on: September 20, 2019, 12:49:15 am »
That is curious.

Consulting Help on ON TIMER, it says "SUB parameter values are passed by value and should be SHARED or literal values!"

Which means even if it would take an array, it would be a temp copy of it and you could not save changed values through the arguments.

Looks like you will have DIM SHARED the array so that SUB would need no arguments.

Oh wait, maybe it's not just one array you want to change... ;(
« Last Edit: September 20, 2019, 08:52:21 am by bplus »

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: On Timer only allows SUB with Integer argument error?
« Reply #3 on: September 20, 2019, 01:34:55 am »
Strings and Arrays are ALWAYS passed as reference (not BYVAL) to any SUB/FUNCTION call according to my findings. Had a similar problem a while back, and did investigate into it as far as possible. It makes sense, as Arrays and Strings arguments in fact are only the start addresses of the string/array, hence references to the actual string/array arguments. In that thinking, it won't probably work with UDTs either (exept if you pass just a single UDT element, not the entire UDT structure).

But as you can use SHARED variables as well to pass variables into a SUB/FUNCTION, I see no reason for bothering the developers, I think SUBs/FUNCTIONs are complicated enough with its internal implementation in QB64.
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: On Timer only allows SUB with Integer argument error?
« Reply #4 on: September 20, 2019, 01:44:40 am »
Is my medication breaking my brain again, or....

****************

EDIT:  Never mind.  My poor brain is broken again.  I was thinking in terms of DECLARE LIBRARY for some reason.  I’m just gonna shut up and go back to bed.  LOL!
« Last Edit: September 20, 2019, 01:50:34 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: On Timer only allows SUB with Integer argument error?
« Reply #5 on: September 20, 2019, 07:07:44 am »
This "error" is not an error. The command ON TIMER simply does not have a specified value from the field, which have to use. I think it's more of a bad combination of commands by the programmer.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: On Timer only allows SUB with Integer argument error?
« Reply #6 on: September 20, 2019, 08:48:36 am »
Strings and Arrays are ALWAYS passed as reference (not BYVAL) to any SUB/FUNCTION call according to my findings. Had a similar problem a while back, and did investigate into it as far as possible....


Which makes the case for ON TIMER that much more curious. It is NOT ALWAYS.

http://qb64.org/wiki/ON_TIMER(n)
  [ You are not allowed to view this attachment ]  

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: On Timer only allows SUB with Integer argument error?
« Reply #7 on: September 20, 2019, 10:18:09 am »
I was just hoping to make a more versatile program an not have anything shared. but ahwell.

Still wonder why a sub called by an on timer would be different than just calling the sub.

But I guess I'll just have to use SHARED. Poomp!
Granted after becoming radioactive I only have a half-life!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: On Timer only allows SUB with Integer argument error?
« Reply #8 on: September 20, 2019, 11:15:24 am »
Big apology, Cobalt. I misunderstood the problem described. This is pretty stupid that the ON TIMER command is studying the parameters of the called subprocess. Why is ON TIMER interested about SUB parameters? It just has to call a subroutine.A really nonsensical restriction.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: On Timer only allows SUB with Integer argument error?
« Reply #9 on: September 20, 2019, 02:13:14 pm »
Which makes the case for ON TIMER that much more curious. It is NOT ALWAYS.

http://qb64.org/wiki/ON_TIMER(n)
  [ You are not allowed to view this attachment ]

I think Rho has hit the nail on the head with: “Strings and Arrays are ALWAYS passed as reference (not BYVAL) to any SUB/FUNCTION”.

ON TIMER *only* accepts values being passed to it BYVAL, (as per the screen shot bplus provides points out), so it can’t accept strings or arrays as a parameter type.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: On Timer only allows SUB with Integer argument error?
« Reply #10 on: September 20, 2019, 02:30:29 pm »
I think Rho has hit the nail on the head with: “Strings and Arrays are ALWAYS passed as reference (not BYVAL) to any SUB/FUNCTION”.

ON TIMER *only* accepts values being passed to it BYVAL, (as per the screen shot bplus provides points out), so it can’t accept strings or arrays as a parameter type.

OH man, I missed the first few words of what Rho said, Strings and arrays, dang! I was skipping over that assuming he was saying all parameters were passed by reference which is true enough that we can pass arrays and change them in a sub and the main code accepts the change.

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: On Timer only allows SUB with Integer argument error?
« Reply #11 on: September 20, 2019, 02:59:32 pm »
And I've an idea why it should be SHARED variables or literals:

Assume you define a variable X in the your main module, which shall be used as parameter to the ON TIMER() DoSomething(X) call...

Now think about the nature of ON TIMER, you define a time interval for the function call, but who says that your program is right executing anywhere in your main module when the interval is elapsed and the DoSomething(X) function is called.

What happens, when your program is executing within any of your SUBs or FUNCTIONs when the timer is ready to call DoSomething(X)? What is passed then? Because variable X is not known in your SUBs/FUNCs unless SHARED or maybe defined as a local X within the SUB/FUNC.

Literals will work always, as it's like a constant value.
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline Jack002

  • Forum Regular
  • Posts: 123
  • Boss, l wanna talk about arrays
    • View Profile
Re: On Timer only allows SUB with Integer argument error?
« Reply #12 on: September 20, 2019, 03:18:20 pm »
I have never used ON TIMER.
The help said this
The ON TIMER statement sets up a timed event to be repeated at specified intervals throughout a program when enabled
So, is it like an interrupt?
If so, I understand the above post. You might be in a function or subroutine somewhere that does not have the scope of this parameter, then it makes sense that it can only take shared vars and literals.

What kinds of things do you use ON TIMER for?
QB64 is the best!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: On Timer only allows SUB with Integer argument error?
« Reply #13 on: September 20, 2019, 03:53:55 pm »
I have never used ON TIMER.
The help said this
The ON TIMER statement sets up a timed event to be repeated at specified intervals throughout a program when enabled
So, is it like an interrupt?
If so, I understand the above post. You might be in a function or subroutine somewhere that does not have the scope of this parameter, then it makes sense that it can only take shared vars and literals.

What kinds of things do you use ON TIMER for?

Yes Rho's reasoning makes sense.

I don't use ON TIMER either, but you can make events happen at regular intervals regardless of what is happening in code, does it actually interrupt a sub? Might be useful in clock making.

Offline Jack002

  • Forum Regular
  • Posts: 123
  • Boss, l wanna talk about arrays
    • View Profile
Re: On Timer only allows SUB with Integer argument error?
« Reply #14 on: September 20, 2019, 04:16:15 pm »
Its useful in games programming. Interrupts are kinda mysterious. Think of two or more programs running concurrently. I think about this hot wheel timer I want to write, the two events you can't miss are when the car enters the first gate, and when it enters the 2nd gate and how much time has elapsed. Basic alone might be too slow to see these events if you need accuracy to 1/1000th a second, interrupts can help with that.  I'm still not to where I have done one yet tho.

I'm sure the mind of a juggler appreciates them. So many tasks going on simultaneously :-)
QB64 is the best!