Hi all -
I'm working with managed structs for the first time, and I'm running into a syntax issue. I've reviewed the manual and some other forum entries but can't figure what I'm doing wrong.
I made a managed struct "Particle" to do some particle effects (floating dust, things like that). I'm having trouble initiating it. Here's the relevant code
Particle* pRaindrops
void LoadParticleArrays() {
pRaindrops = new Particle[1000];
int i;
while (i < 1000 {
pRaindrops[i] = new Particle;
i++;
}
}
function game_start() {
LoadParticleArrays();
}
When I launch the game I get an error "Type mismatch: Cannot convert 'Particle' to 'Particle,'" which is a little baffling.
What am I doing wrong here?
Thanks.
Yes, the error messages in script compiler are often broken. Also, the pointers become weird when used in conjunction with arrays.
In this particular case the problem is that you have declared a single pointer to Particle, which you then treat as a dynamic array.
You would need to declare dynamic array of pointers instead:
Particle* pRaindrops[];
On a side note, AGS supports "for" loop now:
for (int i = 0; i < 1000; i++)
pRaindrops[i] = new Particle;
Thanks - I knew it was something simple. The revised code worked:
Particle* pRaindrops[1000];
void LoadParticleArrays() {
pRaindrops = new Particle;
int i;
while (i < 1000 {
pRaindrops[i] = new Particle;
i++;
}
}
I haven't adopted for loops yet because I got so accustomed to the old-fashioned way. The do/while and switch/case formats have been a great addition, though.