PDA

View Full Version : Little problem with geteventfunc, seteventfunc



Petr Schreiber
23-03-2008, 15:06
Hi Mike,

I had some time to start to play with TBEM module, but I found a little problem which demonstrates following script.
Maybe it is just that I misunderstood something.

The script should add 5 rabbits and 3 wolves ( no, I am not drunk, just test sample ):


uses "CONSOLE"
uses "TBEM"

begin const
%evt_AddElement = 1
end const

Scene_Init()

' -- Prepair events
dim eventAdd as long
eventAdd = TBEM_AddEvent("Scene_AddRabbit", %evt_AddElement)
TBEM_Addtrigger(%evt_AddElement)
TBEM_setRepeat(eventAdd, %TRUE, 1000)

console_PrintLine("Program started, it will add 5 rabbits, 3 wolves and then end :)")

while Scene_Built = 0
' -- Our event loop
TBEM_Run
wend

' -- Aux functions
sub Scene_Init()
Global Scene_Built as long = 0
Global Scene_NumRabbits as long = 0
Global Scene_NumWolves as long = 0
end sub

sub Scene_AddRabbit()

if Scene_NumRabbits = 5 then
TBEM_SetEventFunc(eventAdd, "Scene_AddWolf")
console_printline("-- Time to spawn wolves")
else
incr Scene_NumRabbits
console_printline("Rabbit"+STR$(Scene_NumRabbits)+" added")
endif

end sub

sub Scene_AddWolf()

if Scene_NumWolves = 3 then
TBEM_SetEventFunc(eventAdd, "Scene_AddRabbit")
Scene_Built = 1
else
incr Scene_NumWolves
console_printline("Wolf"+STR$(Scene_NumWolves)+" added")
endif

end sub


After adding 5 rabbits and changing the func to add wolves it GPFs.


Thanks,
Petr

Michael Hartlef
23-03-2008, 17:11
Hi Petr,

sorry for the inconvenience. I didn't test this properly. But I foudn the bug allready and know how to fix it. I will release a new version tonight.

Michael

Petr Schreiber
23-03-2008, 20:04
No problem,

thanks a lot.
Programming dynamic allocation stuff is always dangerous, but when tuned right it is perfect :)


Petr

Michael Hartlef
23-03-2008, 22:22
Hi Petr,

please download the new version from here:

http://community.thinbasic.com/index.php?topic=1624.msg11718#msg11718

It was a pointer bug but should be squished for now.

Petr Schreiber
24-03-2008, 10:04
Thanks for quick fix,

now it works as it should on my PC, very nice!


Petr