# Microbug

Member Since 10 Jan 2012
Offline Last Active Mar 20 2013 05:30 PM

### Drifting Physics - Racing Game

15 March 2013 - 04:16 PM

I'm making a top-down 2d racing game, and the cars can skid in it. At the moment I am using this:
```// acceleration is handled elsewhere
```
but it is too skiddy - I will use it for handbrake turns. Is there any way I can do the same but have the cars less skiddy?

### Rounding To The Nearest 32

17 February 2013 - 07:01 PM

This is (hopefully) fairly simple, but there doesn't seem to be a function for it. In my game, the enemy will follow the player as long as it has line of sight (done with collision_line()). At the moment, the code is something like this:
```if (collision_line(x,y,obj_player.x,obj_player.y,obj_wall,false,true) <= 0 // If there are no instances of obj_wall between this instance and the player
&& player_snapped // and the player is snapped to the grid
&& (obj_player.x == x || obj_player.y == y)) // and the player is in line with this instance (it's x equals my x or it's y equals my y)
{
// Add the player's location into the points array (not shown here)
// Record whether this instance has line of sight
can_see_player = 1;
}
else
{
can_see_player = 0;
}
```
What I want to do is instead of use player_snapped (a global variable defined by me), check whether the player's location snapped to a 32 by 32 grid (with a 16 pixel offset) is in line with the current instance (with a line of sight) and if so, add the player's co-ordinates into the points array. If there is a way to round to 32, doing this with x + 16 and y + 16 should do the trick and that's what I'm looking for. This is so that if the player is going round  a corner but the instance still has line of sight, the instance can chase after it, but not go through a  wall. I have a script called place_snapped_offset(snap,offset) which will return whether the calling instance is snapped with a square grid of size snap offset by offset, if that will help at all.
microbug

### Performing code as all instances of a parent

13 February 2013 - 09:04 PM

How would I go about executing code as all instances of a parent? For example, I have obj_enemy which is the parent of obj_enemy_1, obj_enemy_2 and obj_enemy_3. To do (for example) event_perform(ev_other,ev_user0); as each instance can I do
```with (obj_enemy)
{
event_perform(ev_other,ev_user0;
}
```
or is there some other way.
Thanks

### Adding to the next available 'slot' in an array

11 February 2013 - 07:46 PM

My problem is fairly simple: I have an array called chaser_indexes which contains the ids of instances currently chasing the player. When an instance starts chasing the player, I want it to add it's own id to the array. In other languages this can be done by not specifiying the array index, eg chaser_indexes[] = object_index, but this doesn't work in GML. How can I do this?

### Using a for variable inside a with construction

11 February 2013 - 06:27 PM

This is my code, chaser indexes contains the instance ids of all instances chasing the player
```var index_exists;
index_exists = 0;
// This bit has to be duplicated, as you can't put a with construction within the round brackets of a for loop
with (obj_player)
{
if (chaser_indexes[0] > 0)
{
other.index_exists = true;
}
else
{
other.index_exists = false;
}
}

for (i = 0; index_exists == false; i += 1)
{
with (obj_player)
{
if (chaser_indexes[other.i] > 0)
{
other.index_exists = true;
}
else
{
other.index_exists = false;
}
}
}
```

The first bit works fine, but when it comes to the second part, it says 'Unknown variable chaser_indexes or array index out of bounds'. I know that chaser_indexes exists from the earlier code, so I'm guessing this is because it can't refer to other.i because other.i is from the for loop. However, I have tried doing
`ii = i;`
outside of the with construction and then inside referring to ii, but that still doesn't work. Any ideas?

EDIT: The point of this code is to try to find the highest current value of chaser_indexes and insert the current instance id into the next available slot, if there's a better way to do this please say so!