SOLVED I want my enum be local not global

M

Midastouch

Guest
Hello everyone,
I created an simple inventory system for my player.
It works well, but now i want to have 30 characters, so 30 inventories (you can control each characters)

This is my code for my player 1 :

GML:
slot_under_mouse = 0 //Which slot is under your mouse
inventory_full = 0

for (var i = 0 ; i < 10; i++) {
    for (var j = 0 ; j < 10; j++) {
                inv_p1[i][j] = noone
        }}

enum object_in_slot{
    slot_1,
    slot_2,
    slot_3,
    slot_4,
}

enum object_informations {
    object,
    name,
    description,
    sprite,
}
As you can see i use enmu, the problem is that enum is global.
So if i want to have 30 characters and so 30 inventories.
Must i create an unique enum for each characters?
Or there is a way to put enum local.
Or maybe can i create an someting like that (i tried without success) :

Code:
enum character_name.object_in_slot {
    slot_1,
    slot_2,
    slot_3,
    slot_4,

}


enum character_name.object_informations {
    object,
    name,
    description,
    sprite,
 

Simon Gust

Member
If every inventory behaves the exact same you are fine with a single enum. It works everywhere and for everyone.
Just don't put it inside the create event of that object, put it somewhere... it doesn't have to be run, the compiler will see your enum regardless.
 

TheouAegis

Member
Enums (full name: enumerators) are neither global nor local. They have no function outside the IDE (i.e., Game Maker Studio). They are only there to make your code more readable. When you compile your game, every time the compiler sees "object_in_slot.slot_1" it will replace that with a hard value of 0. Every time it sees "object_in_slot.slot_2" it will replace that with a hard value of 1. You could have enumerators for every character, but in your case it would be utterly pointless.
 
M

Midastouch

Guest
Ok thank you.
And indeed i just put enum somewhere and it works
 
Top