Intro & timer event function call question.

latch

Active Member
Licensed User
Longtime User
I'm latch and have been lurking for a about week...

and my :sign0104: question is, "Can you not call a function within a timer tick event?"

Example:
B4X:
Sub timer_tick
holder="pataflafla"
mitochondriafunction(1)
End Sub

Other commands seem to execute but the functions does not.

I love what you have built, Erel, and thanks to all the rest who have assisted you in this endeavor.

Oddly, I found this place while researching if VB6 code could be compiled on Windows CE. I had an itch for Android dev but I have an aversion to java. Plus I had been searching for a platform for robotics which started with mini ITX(x86) then Raspberry PI(arm11 I believe) and now a4b with IOIO. A cheap electrically economic powerful computer system with a very well supported api and the tech to interface the real world- a dream come true!

Weeeeeeeee! <-nerd glee
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Hi latch,

There should be no problems calling functions from within timer_tick. To help, we are going to need to see some more code, like the timer declaration, initialization and enable, and possibly the called function.

If you can, zip the project (from the file menu) and attach it to your post, it's usually the fastest way to get problems resolved without playing 20 questions.

Steve
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
"Can you not call a function within a timer tick event?"
Definitively the answer is yes. Anyway there is no difference between a function and a subroutine in B4A, you can return a value or not.

So just answering your question I could stop here and waiting for your next question.
But, you dont expalain if you get any error nor what happens.
Nor do you explain what are you doing in the function.

What help do you expect ?

Sorry, but I give you an answer to your question, but I'm frustrated because I can't give you an answer to your problem.
You must give much more explanation on what you want to do, what you have done, what result you are expecting etc .
The best way to get a concrete answer is to post your project source code as a zip file or at least a reduced project showing the problem.

Best regards.
 
Upvote 0

latch

Active Member
Licensed User
Longtime User
Heh, Sorry guys. I'm a member of five other forums(on one I'm a mod) and this is literally the first time I have EVER asked for help on a forum, so bear with me! I didn't want to post the whole project do to the complexity and I am sure I am doing several things wrong in terms of convention and did not want to invite criticism of my odd logic. So I rewrote a boiled down version and this one does appears as though the timer is not firing.

What it is supposed to do is draw a splash screen, wait 2 seconds and move on with the rest of the program(in this case draw another bitmap indicating the function was called from the timer)

You can see at the end of the activity_create event my commented out function call which works when uncommented.

B4X:
'Activity module
Sub Process_Globals

   Dim splashtimer As Timer

End Sub

Sub Globals

   Dim logo As Bitmap
   Dim mainbmp As Bitmap
   Dim Canvas1 As Canvas
   
   Dim Rect As Rect
   Dim lv As LayoutValues
   Dim xc As Float
   Dim yc As Float
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Canvas1.Initialize(Activity)
   logo.Initialize(File.DirAssets, "logo.bmp")
   mainbmp.Initialize(File.DirAssets, "main.bmp")
   splashtimer.Initialize("splashtimer",1000)
   Rect.Initialize(0, 0, 0, 0)
   lv=GetDeviceLayoutValues 
   yc=lv.height/480 
   xc=lv.Width/800

If FirstTime Then 
   Rect.Top = 150*yc
   Rect.Left = 275*xc
   Rect.Bottom = 330*yc
   Rect.Right = 525*xc
   Canvas1.DrawBitmapRotated(logo, Null, Rect, 0)


End If 

' mainscreen(5)

End Sub

Sub Activity_Resume
   splashtimer.enabled = True
End Sub

Sub Activity_Pause (UserClosed As Boolean)
      splashtimer.enabled = False
End Sub


Sub splashtimer_tick

   Rect.Top = 0*yc 'playfield
   Rect.Left = 200*xc
   Rect.Bottom = 20*yc
   Rect.Right = 220*xc
   Canvas1.DrawBitmapRotated(mainbmp, Null, Rect, 0)

   mainscreen(5)
End Sub

Sub mainscreen(nombre As Short)

   Rect.Top = 20*yc 'playfield
   Rect.Left = 200*xc
   Rect.Bottom = 420*yc
   Rect.Right = 600*xc
   Canvas1.DrawBitmapRotated(mainbmp, Null, Rect, 0)

End Sub
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime User
You need to INVALIDATE the activity

B4X:
Sub splashtimer_tick

   Rect.Top = 0*yc 'playfield
   Rect.Left = 200*xc
   Rect.Bottom = 20*yc
   Rect.Right = 220*xc
   Canvas1.DrawBitmapRotated(mainbmp, Null, Rect, 0)
    Activity.Invalidate '<------ ADD THIS LINE.
   mainscreen(5)
End Sub
 
Upvote 0

latch

Active Member
Licensed User
Longtime User
Thank you, sir- the best way for me to learn a language is to read the code of others. So far I've managed to incorporate the following into my project: file access, loops, conditionals, timing, arrays, string manipulation, touch, and graphics.

I just need a few more disciplines, and I can rule the world- uh I mean, finish my project.

No its just a 2d game to cut my teeth on. It reads a text file and builds a maze off of what it finds and I have an on screen game pad that moves the player around the maze-all of which is already working-not bad for 4 days of coding a new language!(a testament to the power and user friendliness of b4a). After I get the enemies running and loaded with unguessable tactics, I'll write a maze editor in VB6 to make the mazes or levels.

What we were resolving here in this thread was just the splashscreen timer which enabled me to get the gametimer working though it turned out I was missing something in my graphics implementation.

RESOLVED!
 
Upvote 0
Top