Page 1 of 1

global var scope?

Posted: Sun Jul 10, 2011 7:47 pm
by Mic
This has to be me :-)

In the Ballz example where iX and iY are declared as vars owned by the model, I have created 2 global vars, mX and mY, and everywhere in the xml where iX, iY are touched, I do the same thing with mX and mY.

And it does not work - only getting 1 model instance where there should be 30. Am checking values with RenderText and mX and mY are behaving.

It is behaving as though

CurrentModel.Position.X += 2*App.DeltaTime * (ballsPosition[mX, mY, X_COORD] - CurrentModel.Position.X); //Model.OnUpdate

the model cannot use global vars to set its position, but this does not compute ... global = global, right?

Not sure whether there is enough info here but thoughts appreciated,

Regards,

Mic

Posted: Sun Jul 10, 2011 7:56 pm
by Kjell
Hmm,

Why would you want to use global variables for the instance index to begin with? Doesn't make a whole lot of sense to me ..

Sounds like you currently do have 30 instances, but they all grab the same position data from the Array ( which makes sense if you're not manipulating the global variables from the instances themselves ), so it appears like there is just one. Check the log for the number of spawned Models in your scene.

K

ah with you ...

Posted: Sun Jul 10, 2011 8:23 pm
by Mic
reason I added the global var was that I could swap models in and out using the same update code - instead of adding iX1, iX2, iX3 for each model. But I think you might be right - I do have 30 but they are superimposed - thanks for the tip. Guess I should find another way of easily substituting models!