Main Menu

But why?? WHY!! HEEEELP

Started by Andreas, June 30, 2008, 08:03:34 AM

Previous topic - Next topic

Andreas

ok I have been looking at this function for 2 days straight now and I need some help.


function pboss_setPos(pBoss,x#,y#)

for each pSys()

if pSys.boss=pBoss
pSys.x# =x#
pSys.y# =y#
playsound laugh
endif

next

endfunction


What it does is simple, step thru all my particles-systems and check pSys.boss to see who is the systems boss.
If pSys.boss=pBoss(only one boss per. system)
then change it's X# and Y# to the passed variables. This function is in my main update loop and I pass mouseX and mouseY to it.
Witch should produce the effect of that all spawned particle systems are locked to the mouse. I spawn 2 systems, pSys.Boss=1 on all of them.

This is what happens: At spawn, they spawn at my mouse cords, and stay there forever. The sample play once. But if I do this..


function pboss_setPos(pBoss,x#,y#)

for each pSys()

if pSys.boss=1
pSys.x# =x#
pSys.y# =y#
playsound laugh
endif

next

endfunction


Then it works. The systems are locked to my mouse and the sound plays like a broken pc. Just like it should.
Then pBoss must be something other then 1. But in the first example the debugger tells me pBoss is 1. ???

Ok then, how about this:
mx# my# =mouse cords



pboss_setPos(1,mx#,my#)

function pboss_setPos(pBoss,x#,y#)

for each pSys()

if pSys.boss=pBoss
pSys.x# =x#
pSys.y# =y#
playsound laugh
endif

next

endfunction


Same result as the first example it set's the position of all spawned systems and they stay there. The sample plays from start to finish.
and the debugger tells me pBoss=1   ???

Any ideas where to start looking? I'm out of them.
I know there might be some problems not having the whole code but I will post it if this yields no fruits.

andreas
The best thing about making space shooters is that space, is easy to draw.

kevin



What is pBoss ?  A type name or variable/constant name?


Andreas


The pBoss variable that is passed to the function, is the identifier of the Particle boss.
I have a type called pBoss and it's list position is the identifier i use for the emitters to know who controls them.

(This is better)

pboss_setPos(1,mx#,my#)

function pboss_setPos(pBossPosition,x#,y#)

for each pSys()

if pSys.boss=pBossPosition
pSys.x# =x#
pSys.y# =y#
playsound laugh
endif

next

endfunction


But when I want to force sevral systems to a position, there is no need to bother him.
All his values are incremented on top of the emitter type linked list values in the emitter update loop.

So I thought to hell with him, and made this function to go thrugh my emitters and see who was bound to the identifier
and force there position. On by one.

Then all the strange stuff started happening.
I'm going to have another go. And carve it out of my game so I can post up some code.


andreas
The best thing about making space shooters is that space, is easy to draw.

kevin


Yes post a snippet as without seeing a working fault,  it's a bit like predicting lotto numbers...

Andreas


I ran this instead and we are working..  ::) Praise the lords of cobol.

pboss_setPos(1,mx#,my#)

function pboss_setPos(pBossPosition,x#,y#)

for each pSys()

if pSys.boss=pBossPosition
pSys.x# =x#
pSys.y# =y#
playsound laugh
endif

next

endfunction


I have no idea why. Is it because i have a type that is also named pBoss maybe..
I have other functions that use pBoss variable to pass info to a function and they work fine.


And thanks for the help. It helps getting the problem aired.

This is kind of a learning project so I'll post up the finished code in the code bank.
Or sooner. Depending on how mutch trouble I get in. ;D

andreas
The best thing about making space shooters is that space, is easy to draw.

kevin

#5
  hmm,  can you post the full broken version. 

   I should point out, that the Type identifiers take global precedence over local variables (or at least they should!)..   So what I think is happening,  is you've stumbled upon a little catch 22 without knowing it..  The compiler is two pass.  Pass #1 only does function/sub prototyping.   During this pass it gets the function names and parameter names/types.  Any variables the pre-parser sees in the declaration header or footer are actually created at this time.  So if you use the token pBoss in the declaration the parse is going to think that it's initially a local within the function scope 

   So at the end of pass #1, it knows the function names and the input/output local variables/types

function pboss_setPos(pBoss,x#,y#)
   

    During Pass #2 it builds the code and handles any variable/type/array declarations.   If we define a TYPE above this function called pBoss then the parser (when building code inside the pBos_SetPos function)  will assume any reference to pBoss is in relation to the global type identifier, rather than the local variable. 

Andreas


Here it is. I have modified it back to how it was as good as i can remember. And the results are there.

I'm not going to insult you with explaining how it works. ::)
It's in pBossFunctions.pba line 118.


andreas
The best thing about making space shooters is that space, is easy to draw.

kevin


Thanks, i'll have a look later.  Wasn't expecting the entire thing though :)

Andreas

#8
Well it solved for me. So I'm happy. :)

but now my tabs in the editor have gone invisable.   :-\

editor 1.1.7b witch is best one?

andreas
The best thing about making space shooters is that space, is easy to draw.