March 05, 2021, 07:20:29 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Like stats
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bb] Multiple Event triggers by ralphy [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Multiple Event triggers by ralphy [ 1+ years ago ] (Read 465 times)
BlitzBot
Jr. Member
Posts: 1
Total likes: 0
[bb] Multiple Event triggers by ralphy [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:42 AM »
Title :
Multiple Event triggers
Author :
ralphy
Posted :
1+ years ago
Description :
Handle multiple events without halting program flow
Code :
Code: BlitzBasic
;Multiple Event Trigger demo
;Useful for handling frame animation for multiple objects instead of using
;the delay or timer functions (they halt program flow).
;Michael Ralph (ralphy)
Graphics
640
,
480
,
16
,
2
SetBuffer
BackBuffer
(
)
;Instead of Globals you could set up your event as a Type collection
;Type Event
; Field eID
; Field clockDelay
; Field lastclock
; Field status
;End Type
Global
event_status =
0
Global
event_lastclock =
0
Global
event2_status =
0
Global
event2_lastclock =
0
Global
event3_status =
0
Global
event3_lastclock =
0
While
KeyHit
(
1
)
=
0
FrameTimer
(
)
; called only once every display update
If
event_status =
1
Then
Text
0
,y,
"Event 1 fired"
y=y+
10
EndIf
If
event2_status =
1
Then
Text
200
,y2,
"Event 2 fired"
y2=y2+
10
EndIf
If
event3_status =
1
Then
Text
400
,y3,
"Event 3 fired"
y3=y3+
10
EndIf
;etc....
Flip
Wend
End
Function
FrameTimer
(
)
event_status =
0
event2_status =
0
event3_status =
0
iclock =
MilliSecs
(
)
; you could iterate your event collection instead of the following...
If
iclock > event_lastclock +
1000
Then
event_lastclock = iclock
event_status =
1
EndIf
If
iclock > event2_lastclock +
500
Then
event2_lastclock = iclock
event2_status =
1
EndIf
If
iclock > event3_lastclock +
300
Then
event3_lastclock = iclock
event3_status =
1
EndIf
End Function
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bb] Multiple Event triggers by ralphy [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal