The Daily Click ::. Forums ::. Klik Coding Help ::. Checking to see if a value is divisible by another value
 

Post Reply  Post Oekaki 
 

Posted By Message

joolsvurn



Registered
  24/05/2010
Points
  60
26th May, 2010 at 19:36:31 -

Hi,

Okay, I am doing a relatively simple 16x16 grid movement, but I have run into a problem when it comes to the AI. My current collision detection for the AI sometimes knocks the NPC off the grid.
I have an easy fix in mind, but I don't know how to execute it.
If I could check if the NPC's current x position and y position is divisible by 16, I will be able to work it out from there.

My question is this: How can I test to see if a value is divisible by 16 in MMF2?

 
It's just a way to stay alive, boy.

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
26th May, 2010 at 19:52:42 -

Try this:

Always: Set some value to X( "Active" ) mod 16.
Value = 0: Do whatever.

The first event sets the value to the remainder after a division of the X position by 16. If the value is 0, 16 divides into it perfectly!

EDIT: Actually I guess you could cut it down to one with the compare two general values condition. X( "Active" ) mod 16 = 0 >> Do whatever.

Edited by OMC

 

  		
  		

joolsvurn



Registered
  24/05/2010
Points
  60
26th May, 2010 at 21:03:06 -

Thank you for the quick response OldManClayton!

It seems by all logic that the mod formula should have worked, but when I implemented it, it caused erratic movement for a reasons I didn't feel like investigating.

What I ended up using was something like this:

X("npc")/16.0 > Int(X("npc")/16) --> do stuff

So basically, comparing the decimal result to the rounded down result. When there isn't decimals, the numbers are equal, meaning it's divisible by 16. When there is decimals, the decimal result is always a larger amount than the rounded down integer.

Anyways, it worked. Thanks for the help!

 
It's just a way to stay alive, boy.

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
26th May, 2010 at 22:49:11 -

Hey, as long as it's working!

 

  		
  		

Xgoff



Registered
  22/02/2009
Points
  135
26th May, 2010 at 23:14:50 -

basically if you're dealing with floating point in any form, you're asking for problems when using equals/not equals

i don't know why mod wouldn't have worked for this though

 
Image

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
26th May, 2010 at 23:20:10 -

I made a concept mfa to test it and it did work, so I don't either. But it's working another way now, so it's no issue!

 

  		
  		
   

Post Reply



 



Advertisement

Worth A Click