I need help

J

James Lin

Guest
if (action_key == true)
{
var inst = instance_create_depth(x, y, -10000, oFists);

if (Equipment_slot_one == "fists")
{
var ex, ey;
ex = instance_nearest(x, y, oEnemy).x;
ey = instance_nearest(x, y, oEnemy).y;
with (inst)
{
direction = point_direction(x, y, ex, ey);
}
}
}
The following code doesn't create a fist.
 

FrostyCat

Redemption Seeker
The code should create a fist, but only if it and the bits setting action_key and Equipment_slot_one are all in the right place.

I just wish rookies would pay as much attention to the placement of their code as the content of their code.
 

curato

Member
One thing I add say is indentation definitely help to see what is dependent on what to happen. Also, if you did indent your code code tag are awesome for preserving that for your forum post.
Code:
if (action_key == true)
{
    var inst = instance_create_depth(x, y, -10000, oFists);

    if (Equipment_slot_one == "fists")
    {
        var ex, ey;
        ex = instance_nearest(x, y, oEnemy).x;
        ey = instance_nearest(x, y, oEnemy).y;
        with (inst)
        {
            direction = point_direction(x, y, ex, ey);
        }
    }
}
Also, I would say make sure you understand with statement they can be powerful, but they can catch you with an odd bug that is hard to track down if you aren't careful. Like in your code you are only assigning one variable in the with this would be equivalent
Code:
inst.direction = point_direction(x, y, ex, ey);
 
P

ParodyKnaveBob

Guest
@curato advises well on using...

[code]
BBCode wrappers
[/code]

...to preserve your indentation. However, a quick correction:
Code:
// after var ex, ey;
with (inst)
{
    direction = point_direction(x, y, ex, ey);
}
...would actually be equivalent to...
Code:
// after var ex, ey;
inst.direction = point_direction(inst.x, inst.y, ex, ey);
...due to assigning to one instance variable but reading from two more.
 
Top