Gamemaker macro error

K

KetoGames

Guest
Gamemaker is giving me the following error whenever I try to load my game:

FATAL ERROR in
action number 1
of Create Event
for object INIT:

Unable to find any instance for object index '1'
at gml_Object_INIT_CreateEvent_1 (line 45) - p99.name = "P99";

So, my INIT object handles all of my initial variable declarations, particle system creations, et cetera. It hasn't ever given me this error before (while working on this project), and the really weird thing is, p99 is a macro (with a value of 1). Usually, this error would come up whenever an instance is missing and then referenced, but what has it got to do with macros?
 

FrostyCat

Redemption Seeker
It has to do with you hard-coding a magic object ID into the macro, and there isn't an instance of that object in the room yet (either because it really isn't there or it comes after your INIT instance in the room's instance order). There's no telling what that object could be.

Instead of putting 1 into the macro, put the actual object ID reference there (i.e. object name without quotes). And make sure there is an instance of it in the room by the time that line runs.
 

Nux

GameMaker Staff
GameMaker Dev.
Dot notation points to a resource, specifically objects.
This means you're pointing to an object with an index of 1.

I'm pretty sure Macros cannot use dot notation; they're constants.
Use enums and an array instead:

Code:
enum type
{
    name = 0,
    data = 1,
    other = 2
}

global.p99[type.name] = "P99";
global.p99[type.data] = "wow this is some cool data";
global.p99[type.other] = "example";
 
K

KetoGames

Guest
Another weird thing. I created another weapon, called wNone (for no weapon), and I set it up the same way, and it seems to work just fine. I have all of my wNone declarations before the p99 declarations, and the error is still thrown with the p99 declarations. Also, there isn't an actual p99 object. The p99 macro just holds information (like the name, type, et cetera).
 

FrostyCat

Redemption Seeker
Dot notation points to a resource, specifically objects.
This means you're pointing to an object with an index of 1.

I'm pretty sure Macros cannot use dot notation; they're constants.
Your GML basic theory needs work.
  • Dot notation doesn't always need to refer to an object, it can also refer to instance IDs and certain special values such as other.
  • A macro can surely be used with dot notation to access instance variables if it refers to a valid object or instance ID.
Another weird thing. I created another weapon, called wNone (for no weapon), and I set it up the same way, and it seems to work just fine. I have all of my wNone declarations before the p99 declarations, and the error is still thrown with the p99 declarations. Also, there isn't an actual p99 object. The p99 macro just holds information (like the name, type, et cetera).
It's a fluke that your code ever worked, that doesn't mean your code is logically sound.

When you did the same with wNone (presumably set to 0), that doesn't mean you've stored info into wNone. What you actually did is storing those properties as instance variables into instances of the object with ID 0, whichever that one may be. The instant you lose those instances or reuse the pattern on some other object ID that doesn't have an instance in the room or doesn't exist at all, your luck goes out.

Instead of attempting to store properties into macros, store properties in an array and use macros to indicate which row to use.
Code:
enum prop { name, type }
// Macro wNone set to 0
global.properties[wNone, prop.name] = "None";
global.properties[wNone, prop.type] = "-";
// Macro p99 set to 1
global.properties[p99, prop.name] = "P99";
global.properties[p99, prop.type] = "Something";
 
K

KetoGames

Guest
Your GML basic theory needs work.
  • Dot notation doesn't always need to refer to an object, it can also refer to instance IDs and certain special values such as other.
  • A macro can surely be used with dot notation to access instance variables if it refers to a valid object or instance ID.

It's a fluke that your code ever worked, that doesn't mean your code is logically sound.

When you did the same with wNone (presumably set to 0), that doesn't mean you've stored info into wNone. What you actually did is storing those properties as instance variables into instances of the object with ID 0, whichever that one may be. The instant you lose those instances or reuse the pattern on some other object ID that doesn't have an instance in the room or doesn't exist at all, your luck goes out.

Instead of attempting to store properties into macros, store properties in an array and use macros to indicate which row to use.
Code:
enum prop { name, type }
// Macro wNone set to 0
global.properties[wNone, prop.name] = "None";
global.properties[wNone, prop.type] = "-";
// Macro p99 set to 1
global.properties[p99, prop.name] = "P99";
global.properties[p99, prop.type] = "Something";
Thank you very much! This makes so much more sense.
 

Nux

GameMaker Staff
GameMaker Dev.
Your GML basic theory needs work.
  • A macro can surely be used with dot notation to access instance variables if it refers to a valid object or instance ID.
I knew this, and frankly any variable containing an integer could point to an item. However, I meant more along the lines of not being able to use dot notation to create a structure type, similar to an object; It was quite obvious that OP was not trying to access an instance.

Anyway, yes, arrays and enums are the way to go.
 
Top