A
aristhemage
Guest
Hi all, with the help of another I have done some world generation for a sandbox game, here is how it generates.
I have an object, sapling, that I want a tree to grow, but this does not work
This creates a visual tree, but crashes the game the second I click (right or left) anywhere, my belief is that it pushes every block a few blocks and gets jumbled on what's what.
If it helps here is the left and right click of things
This is the error:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_player:
Unable to find any instance for object index '101664' name '<undefined>'
at gml_Object_obj_player_Step_0 (line 54) - if (global.world.x == mouseClickX && global.world.y == mouseClickY) {
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_player_Step_0 (line 54)
If you could help me that would be great, I have tried asking my partner, but hasn't responded to anything for a month and a half now, so I assume connections were cut.
Anyways, I'll be here to answer questions, I am not the brightest of programmers, 70% of this code is his.
GML:
//World array
global.world = [];
global.worldArrayLength = 0;
//First two layers
for (var i = 0; i < 80; i++;){
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, 768, "Blocks", block_grass);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, 832, "Blocks", block_dirt);
}
//Ignore this
global.xmem = x
global.ymem = y
//Block name
global.block = "";
//Trees
var wait = 0;
var tree = 0;
for (var i = 0; i < 80; i++)
{
if (--wait <= 0)
{
var chance = random(100);
var tree = irandom_range(0,1)
if (chance < 10) // ~10% chance
{
if tree = 0{
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, 704, "Blocks", block_log);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, 640, "Blocks", block_log);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, 576, "Blocks", block_log);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, 512, "Blocks", block_log);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 - 64, 512, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 + 64, 512, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 - 128, 448, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 - 64, 448, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, 448, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 + 64, 448, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 + 128, 448, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 + 64, 384, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 , 384, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 - 64, 384, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 , 320, "Blocks", block_leaves);
}
if tree = 1{
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, 704, "Blocks", block_log);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, 640, "Blocks", block_log);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, 576, "Blocks", block_log);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, 512, "Blocks", block_log);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, 448, "Blocks", block_log);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 - 64, 448, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 + 64, 448, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 - 128, 384, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 - 64, 384, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, 384, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 + 64,384, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 + 128,384, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 + 64, 320, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 , 320,"Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 - 64, 320, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(i * 64 , 256, "Blocks", block_leaves);
}
wait = irandom_range(3, 6);
}
}
}
//"Cave" System
for (var i = 0; i < 80; i++;){
for (var b = 0; b < 30; b++;){
if b < 10{
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, b*64+896, "Blocks", block_stone);
}else
{
var number = irandom_range(0,10);
if number > 6
{
global.world[global.worldArrayLength++] = instance_create_layer(i * 64, b*64+896, "Blocks", block_stone);
}else
{
}
}
}
}
GML:
global.world[global.worldArrayLength++] = instance_create_layer(x, y, "Blocks", block_log);
global.world[global.worldArrayLength++] = instance_create_layer(x, y-64, "Blocks", block_log);
global.world[global.worldArrayLength++] = instance_create_layer(x, y-128, "Blocks", block_log);
global.world[global.worldArrayLength++] = instance_create_layer(x, y-192, "Blocks", block_log);
global.world[global.worldArrayLength++] = instance_create_layer(x, y-256, "Blocks", block_log);
global.world[global.worldArrayLength++] = instance_create_layer(x - 64, y-256, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(x + 64, y-256, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(x - 128, y-320, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(x - 64, y-320, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(x, y-320, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(x + 64,y-320, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(x + 128,y-320, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(x + 64, y-384, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(x , y-384,"Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(x - 64, y-384, "Blocks", block_leaves);
global.world[global.worldArrayLength++] = instance_create_layer(x , y-448, "Blocks", block_leaves);
If it helps here is the left and right click of things
GML:
if (mouse_check_button_released(mb_left)) {
var mouseClickX = floor(mouse_x / blockSize) * blockSize;
var mouseClickY = floor(mouse_y / blockSize) * blockSize;
var blockClicked = undefined;
var blockClickedIndex = undefined;
for (var i = 0; i < array_length_1d(global.world); i++) {
if (global.world[i].x == mouseClickX && global.world[i].y == mouseClickY) {
blockClicked = global.world[i];
blockClickedIndex = i;
}
}
if (blockClicked != undefined) { // if there was a block on the position you clicked
var isInRange = point_distance(obj_player.x, obj_player.y, blockClicked.x, blockClicked.y) <= playerAttackRange;
if (isInRange) {blockClicked.hp -= playerAttackDamage;}
if (blockClicked.hp <= 0) {
instance_destroy(blockClicked); // to remove the actual object from the game
global.world = remove_from_array(global.world, [blockClickedIndex]); // to remove the object from the 'global.world' array
}
}
}
if (mouse_check_button_released(mb_right)) {
var mouseClickX = floor(mouse_x / blockSize) * blockSize;
var mouseClickY = floor(mouse_y / blockSize) * blockSize;
var blockClicked = undefined
for (var i = 0; i < array_length_1d(global.world); i++) {
if (global.world[i].x == mouseClickX && global.world[i].y == mouseClickY) {
blockClicked = global.world[i];
blockClickedIndex = i;
}
}
if (global.inventory[global.slot * 4] < 20 && global.inventory[global.slot * 4 + 1] > 0) {
if blockClicked == undefined{
var blockCreated = instance_create_layer(mouseClickX, mouseClickY, "Blocks",global.inventory[global.slot * 4 + 3]);
global.world[array_length_1d(global.world)] = blockCreated;
global.inventory[global.slot*4+1] -= 1;
}
}
}
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_player:
Unable to find any instance for object index '101664' name '<undefined>'
at gml_Object_obj_player_Step_0 (line 54) - if (global.world.x == mouseClickX && global.world.y == mouseClickY) {
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_player_Step_0 (line 54)
If you could help me that would be great, I have tried asking my partner, but hasn't responded to anything for a month and a half now, so I assume connections were cut.
Anyways, I'll be here to answer questions, I am not the brightest of programmers, 70% of this code is his.