T
Taycamgame
Guest
I'm working on an RPG and it will have keys and locked doors / blocks. Keys will be limited to the dungeon they are found in (so you can't use a key from dungeon 1 in dungeon 2 etc.).
I have the following in the create event for the object obj_game:
LEVEL_COUNT is a macro which is just the number of levels.
Each key has a variable dungeon assigned to it, this is what number dungeon the key can be used in.
When the player collides with a key:
And the collectKey function:
This code just adds 1 key to the number they have in the correct dungeon.
Next, the player's collision check with the locked blocks:
And the unlockBlock function:
This goes through the global.keysNormal array, looks for the dungeon and compares the number of keys they have. If they have atleast one key, the door unlocks (destroys) and the number of keys is reduced.
And basically what this does is setup an array, e.g. when LEVEL_COUNT is 2 then the global.keysNormal array will start off as [0, 0]. If a key in dungeon 1 is collected this array goes to [1, 0]. If a door is unlocked then it will remove one key from the correct dungeon.
The problem i have is that, if the player collects a key or unlocks a door, and leaves the room and returns, then the key / door will reappear. This does not change the value in the array so the player could get basically infinite keys. How do i make it so that collected keys and unlocked doors don't reappear when they shouldn't?
I have the following in the create event for the object obj_game:
Code:
//Keys
global.keysNormal = array_create(LEVEL_COUNT, 0)
Each key has a variable dungeon assigned to it, this is what number dungeon the key can be used in.
When the player collides with a key:
Code:
collectKey(other.dungeon)
instance_destroy(other)
Code:
function collectKey(_dungeon){
for (var i = 0; i < array_length(global.keysNormal); i ++){
if (i == _dungeon){
global.keysNormal[i] += 1
}
}
show_debug_message(global.keysNormal)
}
Next, the player's collision check with the locked blocks:
Code:
unlockBlock(other.dungeon, other)
Code:
function unlockBlock(_dungeon, _other){
for (var i = 0; i < array_length(global.keysNormal); i++){
if (i == _dungeon){
if (global.keysNormal[i] > 0){
global.keysNormal[i] -= 1
instance_destroy(_other)
}
}
}
show_debug_message(global.keysNormal)
}
And basically what this does is setup an array, e.g. when LEVEL_COUNT is 2 then the global.keysNormal array will start off as [0, 0]. If a key in dungeon 1 is collected this array goes to [1, 0]. If a door is unlocked then it will remove one key from the correct dungeon.
The problem i have is that, if the player collects a key or unlocks a door, and leaves the room and returns, then the key / door will reappear. This does not change the value in the array so the player could get basically infinite keys. How do i make it so that collected keys and unlocked doors don't reappear when they shouldn't?