Odd Behaviour

Blitz3D Forums/Blitz3D Programming/Odd Behaviour

MadMax(Posted 2003) [#1]
I'm making a small silly program in 2D (using B3D) and I noticed that the first time I hit keyhit(x) the program would stall, but only the first time I hit the key. Now what this key does is create a bullet. Now if I create a bullet before the main loop this doesn't happen, but I get a bullet flying of as soon a the program starts. Seems to me that the first time a defined type is created hits the CPU quite hard.

My question: Is there a way to avoid having to fire a bullet before the program starts?


GfK(Posted 2003) [#2]
Are you loading an object each time a key is pressed?

It seems that its taking time to load it the first time, but for subsequent bullets, the object file will be cached and so would load far quicker.

Maybe you could post some code?


MadMax(Posted 2003) [#3]
Doesn't load anything all it does is

tiro.bala = new bala

tiro\x=nx
tiro\y=460


and it only happens the first time the key is pressed in the game.


semar(Posted 2003) [#4]
Odd..

Try with:
1) put a Flushkeys() before the main loop starts

OR

2) create a bullet before the main loop, and then delete it, before the main loop starts

OR

3) Did you declared tiro as global ?
Global tiro.bala

Very odd. Does it do the same with B2D - assuming you have it - ?

Are there other models/images that are loaded in the main loop ? Every load... command should stay outside the main loop.

Sergio.


Anthony Flack(Posted 2003) [#5]
This shouldn't happen. I think there may be a sneaky little problem hiding somewhere in your code.


MadMax(Posted 2003) [#6]
I isolated the offending code, and guess what! It works fine. So they may be something else that causes this.

I'll pursue the matter, but I still find it very odd. It's just when I add both codes together.

Hmmm. quite confusing at the moment. It only stalls the first time I shoot the bullet, and if I create a dummy bullet before the main loop then everything works fine. Think I'll try and see if it behaves in the same way in B+ and the B2d full-demo I got from a magazine.