Jump to content


Photo

Tower Defense Pathing Error?

gm:studio

  • Please log in to reply
No replies to this topic

#1 Ghoststalker

Ghoststalker

    GMC Member

  • GMC Member
  • 21 posts
  • Version:GM:Studio

Posted 29 March 2016 - 08:51 AM

I am currently in the beginning stages of creating a Tower Defense game. Just about everything was working just fine, then I went and reorganized some of the code so as to be able to have a controller object that can control multiple of child objects in the future without having to add much extra code. However after I did this I get an error whenever I go to place a turret to test the game.

Variable obj_lake.pos(100003, -2147483648) not set before reading it.
 at gml_Object_obj_controller_GlobalRightButtonPressed_1 (line 18) -                         xx = path_get_point_x(global.path, pos);

The code in question happens to be:

// IN obj_controller

// IN GLOB RIGHT PRESSED_1 EVENT

var snap_x = (mouse_x div 32) * 32;
var snap_y = (mouse_y div 32) * 32;

var inst = instance_position(snap_x, snap_y, obj_turret);

if instance_exists(inst)
    {
        with (inst) instance_destroy();
    }
    else
    {
        inst = instance_create(snap_x, snap_y, obj_turret);
        with(inst) mp_grid_add_instances(global.AI_grid, id, false);
        if scr_Define_Path()
            {
                with (obj_enemy_spawn)
                    {
(line 18)               xx = path_get_point_x(global.path, pos);
                        yy = path_get_point_y(global.path, pos);
                    }
            }
            else with (inst) instance_destroy();
    }

Other relevant code in the controller object that may be playing into this:

// IN obj_controller

// IN CREATE EVENT

global.AI_grid = mp_grid_create(0, 0, room_width/64, room_height/64, 64, 64);
global.path = path_add();

mp_grid_add_instances(global.AI_grid, obj_turret, false);

scr_Define_Path();


// IN ROOM END EVENT

path_delete(global.path);
mp_grid_destroy(global.AI_grid);

Other possibly relevant code:

// IN obj_water_drop (enemy)

// IN CREATE EVENT

hp = 30

pos = 1;
xx = path_get_point_x(global.path, pos);
yy = path_get_point_y(global.path, pos);


// IN STEP EVENT

if (hp <= 0) instance_destroy();

if point_distance(x, y, xx, yy) < 6
    {
        pos++;
        if pos = path_get_number(global.path)
            {
                instance_destroy();
            }
            else
            {
(line 18)       xx = path_get_point_x(global.path, pos);
                yy = path_get_point_y(global.path, pos);
            }
    }
mp_potential_step(xx, yy, 3, false);

Any code within obj_lake or obj_enemy_spawn (a controller object) would be irrelevant because they only contain code dealing with eneny spawning and the only enemy so far is the water drop (obj_water_drop).

 

Also a fair amount of this code is from this tutorial:

http://help.yoyogame...ds-To-Create-AI

which I have been looking back upon as to find a solution, but so far I have found nothing that helps.


Edited by Ghoststalker, 29 March 2016 - 08:51 AM.

  • 0





Also tagged with one or more of these keywords: gm:studio