Error *Help

L

Logan Bevans

Guest
Hello I'm following a tutorial and i can't get it to work any help would be greatly appreciated

Error Code:
FATAL ERROR in
action number 1
of Step Event0
for object obj_player:

Pop :: Execution Error - Variable Index [0,-54] out of range [1,55] - -5.ah(100026,-54)
at gml_Script_scr_worldgen (line 19) - for(xx = starting_room; xx < ending_room; xx += 32) {
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_scr_worldgen (line 19)
called from - gml_Object_obj_player_StepNormalEvent_1 (line 142) - global.chunk2 = scr_worldgen(global.chunk2 - 3456);



Link to Tutorial:

scr_worldgen: --------
var sh,ah,dirt_level,stone_level,water_level,adl,starting_room,ending_room, tree, biome,hill;
sh = 1920;
randomize();
//Starting Height
ah = sh;


starting_room = argument0;
ending_room = argument0 + 1728;

tree = choose(1);
biome = choose(1,2,3);
hill = choose(true,false,false);

for(i=0;i<55;i+=1) {
global.ah = 0;
}

for(xx = starting_room; xx < ending_room; xx += 32) {

if biome = 1{

//Biomes
//------PLAINS------//
instance_create(xx,ah,obj_grass);

dirt_level = ah + 32*choose(2,3,3,3);
stone_level = 4192; //room_height poss inf down
water_level = 1920;

//Dirt Level
for(yy = ah; yy < dirt_level; yy += 32){
instance_create(xx, yy + 32, obj_dirt);
adl = yy
}
//Stone Level
for(yy = adl; yy < adl + 64; yy += 32){
u = round(random(choose(3)));
if u = 1{
instance_create(xx, yy + 64, obj_stone);
}else {
instance_create(xx, yy + 64, obj_dirt);
}
}
for(yy = adl + 64; yy < stone_level; yy += 32){
instance_create(xx, yy + 64, obj_stone);
}
//Height Variation In Biome
if (hill){
amp = 7;
} else {
amp = 5 + random(4);
}
ah += amp*sin((2*pi)/1728*(xx-864))+((8+random(8))*sin((2*pi)/choose(54,108,240)*xx))+((15+random(2))*sin((2*pi/240)*xx));
}

if biome = 2{
///-----PLAINSwTrees--///

instance_create(xx,ah,obj_grass);

//global.th = choose(5,6,6,6,6,6,7,7,7);
global.th = choose(5);
dirt_level = ah + 32*choose(2,3,3,3);
stone_level = 4192; //room_height poss inf down
water_level = 1920;
if (ah <= water_level){
tree += 1;
}

//Trees
if (tree = 9) && (ah <= water_level){
c = choose(1,1,2);
if c = 1{
with(instance_create(xx,ah - 32,choose(obj_logspawn_oak,obj_logspawn_birch))){
canGrow = true;
}
}
tree = choose(1,2,2,3,3,4,4,5);
}
//Dirt Level
for(yy = ah; yy < dirt_level; yy += 32){
instance_create(xx, yy + 32, obj_dirt);
adl = yy
}
//Stone Level
for(yy = adl; yy < adl + 64; yy += 32){
u = round(random(choose(3)));
if u = 1{
instance_create(xx, yy + 64, obj_stone);
}else {
instance_create(xx, yy + 64, obj_dirt);
}
}
for(yy = adl + 64; yy < stone_level; yy += 32){
instance_create(xx, yy + 64, obj_stone);
}
//Height Variation In Biome
if (hill) {
amp = 16;
} else {
amp = 10 + random(4);
}
ah += amp*sin((2*pi)/1728*(xx-864))+((8+random(8))*sin((2*pi)/choose(54,108,240)*xx))+((15+random(2))*sin((2*pi/240)*xx));
}

if biome = 3{
/// ----FOREST----/////
instance_create(xx,ah,obj_grass);

global.th = choose(5,6,6,6,6,6,7,7,7);
dirt_level = ah + 32*choose(2,3,3,3);
stone_level = 4192; //room_height poss inf down
water_level = 1920;
if (ah <= water_level){
tree += 1;
}
//Trees
if (tree = 9) && (ah <= water_level){
c = choose(1,1,2);
if c = 1{
with(instance_create(xx,ah - 32,choose(obj_logspawn_oak,obj_logspawn_birch))){
canGrow = true;
}
}
tree = choose(2,3,3,4);
}
//Dirt Level
for(yy = ah; yy < dirt_level; yy += 32){
instance_create(xx, yy + 32, obj_dirt);
adl = yy
}
//Stone Level
for(yy = adl; yy < adl + 64; yy += 32){
u = round(random(choose(3)));
if u = 1{
instance_create(xx, yy + 64, obj_stone);
}else {
instance_create(xx, yy + 64, obj_dirt);
}
}
for(yy = adl + 64; yy < stone_level; yy += 32){
instance_create(xx, yy + 64, obj_stone);
}
//Height Variation In Biome
if (hill) {
amp = 16;
} else {
amp = 10 + random(4);
}
ah += amp*sin((2*pi)/1728*(xx-864))+((8+random(8))*sin((2*pi)/choose(54,108,240)*xx))+((15+random(2))*sin((2*pi/240)*xx));
}
for(yy=ah-320;yy<ah;yy+=32){
instance_create(xx,yy,obj_empty);
}
global.ah[xx/32] = ah;
}


return ending_room;
 

YoSniper

Member
I really hope that you are understanding the context of your code, rather than just copying and pasting.

The error you are getting is an index error, meaning you are trying to call from a slot in an array that does not exist. In this case, it looks like global.ah exist for all i in [0, 54], but you're trying to call global.ah[-54].

Looking through your code, I think that one of the parts of the problem is here:
Code:
for(i=0;i<55;i+=1) {
global.ah = 0;
}
In this loop, you are merely resetting the same variable to the same value 55 times. What I think you want to do is this:
Code:
for(i = 0; i < 55; i += 1) {
    global.ah[i] = 0;
}
This initializes 55 indexes of an array each to 0.

The second part of your problem is that xx does not appear to be restricted to the range of 0 to 32 * 54 (whatever that is, I'm too lazy to calculate it.)
My guess is that you are calling the script with the starting_room argument being a negative number, specifically whatever -54 * 32 is. So the very last line of the script is trying to call global.ah[-54] and there's your error.

I hope that this helps you on your way.
 

FrostyCat

Redemption Seeker
Also, start posting your code between [code] and [/code] tags. This is something that newcomers these days omit a lot, and if they took the time to read the posting guidelines they would have known better.

When people fail to use [code] and [/code] tags, the posted code loses all indentations, and certain common fragments of code get misinterpreted as BBcode for formatting (particularly [i] for italics). It makes their code hard to read and sometimes hides important details.
 

YoSniper

Member
When people fail to use [code] and [/code] tags, the posted code loses all indentations, and certain common fragments of code get misinterpreted as BBcode for formatting (particularly [i] for italics). It makes their code hard to read and sometimes hides important details.
This makes a lot of sense. As such, the first part of my solution can be ignored, but I still think you're giving bad arguments to the script, causing it to look for a nonexistent index.
 
L

Logan Bevans

Guest
This makes a lot of sense. As such, the first part of my solution can be ignored, but I still think you're giving bad arguments to the script, causing it to look for a nonexistent index.
Ahh yeah im going through the tutorial to add key features that i do not fully understand how to implement on my own for those codes i write word for word ill take a look and see if i can figure it out
 
L

Logan Bevans

Guest
I really hope that you are understanding the context of your code, rather than just copying and pasting.

The error you are getting is an index error, meaning you are trying to call from a slot in an array that does not exist. In this case, it looks like global.ah exist for all i in [0, 54], but you're trying to call global.ah[-54].

Looking through your code, I think that one of the parts of the problem is here:
Code:
for(i=0;i<55;i+=1) {
global.ah = 0;
}
In this loop, you are merely resetting the same variable to the same value 55 times. What I think you want to do is this:
Code:
for(i = 0; i < 55; i += 1) {
    global.ah[i] = 0;
}
This initializes 55 indexes of an array each to 0.

The second part of your problem is that xx does not appear to be restricted to the range of 0 to 32 * 54 (whatever that is, I'm too lazy to calculate it.)
My guess is that you are calling the script with the starting_room argument being a negative number, specifically whatever -54 * 32 is. So the very last line of the script is trying to call global.ah[-54] and there's your error.

I hope that this helps you on your way.
ahh yeah i accidently took out the though it still gave me the same issue ill take a look through other aspects of the code to see if i can figure it out
 
Top