How Do Yo Check if a Level is a Multiple of 10?

Blitz3D Forums/Blitz3D Beginners Area/How Do Yo Check if a Level is a Multiple of 10?

Crazy4Code(Posted 2005) [#1]
I'm probably missing some very easy mathematical equation, but, I want to check if the player is on level 10,20,30, and so on. If that happens, a boss will appear, but how do I check if a level is a multiple of 10?


sswift(Posted 2005) [#2]
IF X MOD 10 = 0 Then X divides by 10 evenly, with no remainder.


Crazy4Code(Posted 2005) [#3]
IT works, thanks! I didn't know about mod


Najdorf(Posted 2005) [#4]
the thing I don't like of mod is that it does not work for negative numbers: when I write "-7 mod 10" I expect to get 3, not -7. Anyway its easy to code one's mod.

Anyway the syntax is

IF X MOD 10 = 0 Then makebossappear(cool, powerfull, supemissiles)


Shagwana(Posted 2005) [#5]
Theres anohter potential way,
if int(x/10)*10 = x
  ;Devidable by 10
  else
  ;Not devidable by 10
  endif

mute point tho, as sswifts provided the answer! :)


Rook Zimbabwe(Posted 2005) [#6]
I am still shakey on MOD squad myself so I would divide the number by 10 and then by itself... if the answer was exactly 1 then viola! you have achieved another level of base 10.

RZ


Vorderman(Posted 2005) [#7]
MOD just gives you the remainder after dividing by the specified number - if it's 0 then the number divides into the original exactly.

just use ABS(X) MOD 10 to avoid probs with negative numbers, but then you shouldn't have a level numbered below 1 anyway I would think.


Sir Gak(Posted 2005) [#8]
Najdorf:
the thing I don't like of mod is that it does not work for negative numbers: when I write "-7 mod 10" I expect to get 3, not -7.

MOD still gives a zero answer on multiples of -10, i.e.,

IF X MOD 10 = 0 Then makebossappear(cool, powerfull, supemissiles)

will still work at -10, -20, etc, for multiples of 10


Lane(Posted 2005) [#9]
Regardless you could use

If MOD abs(10) = o then makebossappear(cool, powerfull, supemissiles)

abs is absolute value.. makes a neg number a pos and leaves pos as pos.


jfk EO-11110(Posted 2005) [#10]
shagwana - better don't use INT this way since it will round floats. Instead use
x_floor=floor(x/10)*10
if x - x_floor = 0
  ;multiple of 10
  else
  ;Not multiple of 10
  endif



Neochrome(Posted 2005) [#11]
function qWrap(Quick,low,high)
if quick>high then quick=low
if quick<low then quick=high
return quick
end function

works for me. if your using whole numbers


Damien Sturdy(Posted 2005) [#12]
Neo, What happens when you Qwrap(15,0,10)? You get 0, not 5 :P

ABS(X) MOD 10 as Vorderman said.... will do :)