# the_hyrax_lord

Member Since 06 Aug 2006
Offline Last Active Dec 06 2012 02:04 AM

### Checking if x is a multiple of a number

30 October 2011 - 02:43 PM

I plan to have a rare event in my game which occurs when a certain object's x and y are equal to the center of a grid space (my game room is split into 32x32 tiles).  The object in question has its origins centered, so what I need is something like

`if x=(a multiple of 32)+16 && y=(a multiple of 32)+16`

I thought of doing 'if x/32=(an integer)', but again, I couldn't figure out how to do that.  Apparently my maths/gml sucks; I'm sure I'm completely overlooking something simple.

### Discrete, Snapped Movement

11 October 2011 - 03:52 PM

First a quick question on depth: I have a control object which is handling quite a few things in my game, including drawing the HUD, so its depth is set higher than everything else in game.  However, it's also responsible for drawing something else which needs to be set below (behind) another object in the room.  Can I do that?  It was originally two separate objects, but I combined them hoping to cut back on objects; it was only on a playtest that I realised this.

My second question is my main one, now that's out of the way.  I'm currently using this code for movement of NPCs:

```target=argument0
var g;

g=instance_nearest(x,y,target)
x += sign(g.x - x) * 32;
y += sign(g.y - y) * 32;```

It works, but as you can see there's no sort of obstacle detection.  I'd like to adapt this code to have it avoid, say, o_solid.  I've tried some motion planning but in the end it didn't seem to work out for my particular needs, so I reverted to this, which I at least know works as I'd like.

### Variable1 = object with (variable2 = x)

30 September 2011 - 05:18 PM

I need to do something like this:

if objX exists && objX.creator=id
{
target=thatparticularinstance
}

There can be an indefinite amount of objX, but I need 'target' to only be the objX whose 'creator' variable is equal to the id of the instance the code is running in. I know how to check for such an instance, but I can't work out how to say, for example, 'c=objX(with creator=id)' - how to specify the one I need.

at the moment, I'm using this code in the Create event of an 'o_target':

```temp=instance_create(x,y,o_targetstub)
temp.creator=global.selected```

global.selected holds the id of a currently selected instance. So every 'o_targetstub' (an invisible object) has as its 'creator' variable the id of the selected instance at its creation. However, 'o_targetstub's don't get deleted when a different instance is selected, and are still relevant to the instance that WAS selected at their creation.

instance1 therefore needs to keep referencing the same o_targetstub (ie the one that was created while it was selected), even while instance2 is selected.

### Instance nearest - 2 object types - *SOLVED*

28 September 2011 - 08:18 PM

Basically I need to have an object find out which is closest between two object types, and it isn't feasible to use a parent object in this case. At least I can't see any way to do that. Here's why.

There are 9 different objects - 4 patrol objects, and 5 different types of building they can visit. However, each patrol object can only visit the central building, and buildings of one other type. eg, opatrol1 can only visit ocentral and obuilding1, opatrol2 can only visit ocentral and obuilding2, etc. So I need each patrol object to search to see whether ocentral or an obuildingX is nearest. I can't parent the obuildings to ocentral because then all patrols could visit all buildings.

### Moving a drawn sprite (not an object)

26 September 2011 - 07:09 PM

I was originally using backgrounds to create rain in my game (when it was raining, I made a certain background visible, otherwise it was off).  It worked fine, but it drew over the top of my HUD and some other elements I wanted drawn above the rain.  So now I'm using 'draw_sprite_tiled' instead, in order to have more control of the depth.  However, I'm not sure now how to incorporate the hspeed and vspeed elements of the background, without having the rain be a new object (rather than just drawn as a sprite in the Draw event of a control object which also controls other things in the game).

Also, still having trouble with this issue.