Pregunta

First time posting here so I'm not completely sure how this goes, but a friend told me to post my problem here, so here goes.

I'm using Game Maker 8.1 for a simple project, and I've come to a halt due to not knowing how to find a multiple of a variable.

I currently have this code:

if step = 941 || step = 941 + 205*1 || step = 941 + 205*2 || step = 941 + 205*3 || step = 941 + 205*4
{
    alarm[0] = 1
}

"step" is a variable that an object is adding +1 every frame.

Now what I want to do is that this function fires itself when the step variable is either 941, or 941 + any multiple of 205 (as in 205, 410, 615, 820, etc)

I tried using the mod function (%), but

if step = 941 || step = 941 mod 205
{
    alarm[0] = 1
}

didn't work, so now I'm stuck.

I really don't feel like putting every 205 manually, but I'll do it IF there's no other option.

Thanks in advance, and sorry for the trouble.

¿Fue útil?

Solución

I'm not familiar with Game Maker but mod returns the remainder of a division. 941 isn't a multiple of 205 so the test wouldn't act the way you intend for it to. Subtract 941 from step so that you're left with 205 * n which you can then check to see if mod 205 results in 0 (no remainder means it's a multiple).

Something like this, maybe:

if (step - 941) mod 205 = 0
{
    alarm[0] = 1
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top