GameMaker HELP ME PLEASE

J

Joshua Hotchin

Guest
Hey everyone,
This sh*t is driving me insane and idk why its happening.
It an instances create event it is
Code:
if (global.hasgun)
{
    target = rLvTwo;
}
else
{
    target = rEnding;
}
but when hasgun == true it sends me to rEnding and gives me an error saying
tryig to index a varriable which is not an array at gml_Object_oEnding_Create_0 (line to) - length = string_length(endtext[currentline]);
and here is my oEnding create event:
Code:
stats = "Stats:\nKills: " + string(global.kills) + " \nDeaths: " + string(global.deaths) + " \nSigns read: " + string(global.signsread) + "\nJumps: " + string(global.jumps) + "\nShots fired: " + string(global.shotsfired) + "\nTimes song skipped: " + string(global.musicskips) + "\nEnemy shots fired: " + string(global.enemyshotsfired) + "\nItems picked up: " + string(global.itempickups);

gunsprite = layer_sprite_get_id("TitleAssets","gGun");
if (global.hasgun == true) && (global.kills > 0)
{
    endtext[0] = "And on this day our hero had slain " + string(global.kills) + " people.";
    if (global.kills == 1) endtext[0] = "And on this day our hero killed a guy for no reason.";
    endtext[1] = "But some of those people had guns too, so...";
    endtext[2] = "He was probably saving the world, or something.";
    endtext[3] = "Regardless, he was arrested two days later spent the rest of his life in prison.";
    endtext[4] = "The defense team tried to argue that the sexy recoil effects and hit flashes were to blame,\nbut to no avail.";
    endtext[5] = "The park ranger would later state she was \"not angry, just disappointed.\"";
    endtext[6] = "The end!";
    endtext[7] = stats;
}

if (global.cheated == true)
{
    endtext[0] = "WOW! You completed the game with a gun without killing anyone!\nYou should be a police officer or something.\nNo, seriously. How did you do it.\n1. It would take forever to complete the game without killing anyone, and\n2. How did you get through the game without dying???\nDid you hack the game or something?\nAnyway, well done!!!";
    endtext[1] = "The end!";
    endtext[2] = "*cough* cheater *cough*";
    endtext[3] = "Seriously though, you are a cheater. Honestly not possible what you did!";
    endtext[4] = "And for cheating you will not be punished, you will have to sit here and read all of these messages.";
    endtext[5] = "MWWHAHAHHA!!\nHow evil of me?\nI mean, you could press escape and return to the main menu :(";
    endtext[6] = "Just do it, I know you want to.\nNo one want to talk to me.\nThe lonely narrator!";
    endtext[7] = "Honestly, goodbye.\nJust press escape now!";
    endtext[8] = "Ok, I am sorry for trying to punish you.\nGoodbye!";
    endtext[9] = "Bye!\nLeave NOW!!\nLEAVE NOW!!!\nNOW!!";
    endtext[10] = "Ok, I am leaving now\nGoodbye!";
    endtext[11] = "BYEEEE!!!!";
    endtext[12] = "The end!";
}

if (global.hasgun == false)
{
    layer_sprite_destroy(gunsprite);
    endtext[0] = "That was all, our player had decided not to pick\ntheir gun so therefor the game was over!";
    endtext[1] = "The end!";
}

if (global.doesntwanttoplay == true)
{
    endtext[0] = "It turns out our player didn't want to play this game.\nSo they decided to go back to their life.";
    endtext[1] = "The end!";
}

spd = 0.5;
letters = 0;
currentline = 0;
length = string_length(endtext[currentline]);
text = "";
if anyone could please help me that would be great!!!!!!!
 
D

dannyjenn

Guest
I don't know why it's taking you to rEnding, but the error message is probably due to endtext[0] never being initialized. I'd change your if statement (global.cheated==false) to (global.kills<=0).

Also, this has nothing to do with the error message, but I'd say that those if statements should probably be changed into else if statements. Also, you should move them around such that the bottom one comes first, the third one comes second, the second one comes third, and the first one comes last. The way you have it right now, you're probably going to run into problems.
 
Looking this over here... Perhaps try actually setting a value for the game to check global.hasGun for. In your case, you'd ask if global.hasGun = true. I don't know if this will help, but it will rule out any possible quirks with just expecting GameMaker to know what you're asking for.

~Pir
 
Top