Hello everyone, I would like to create a puzzle system where, when you start the game, there is no key on a table for example, but once you unlock a certain dialogue, the key appears. And only if you have picked up the key should the door you want to open actually open. That’s it — if anyone knows a tutorial or could explain how to do this, I’d really appreciate it.
#Need Help with Puzzle system
7 messages · Page 1 of 1 (latest)
You would want to create one or more global variables which represent your player's progress through the game.
When the room with the table/key loads, make the key object check to see whether the player has progressed to the stage where the key should be there.
If they are at a stage where the key should not be there, make the key instance destroy itself.
I typically use a global struct for this. And my typical setup would be for multiple quests whose progress is tracked independently.
If you only have a single thing which needs tracking, you could just use a number.
Here is an example of a very basic implementation.
At game start:
global.game_progress = 0;
When the dialogue which allows the key to appear happens for the first time:
global.game_progress = 1;
On the key instance:
if (global.game_progress != 1){
instance_destroy();
}
When the key gets picked up:
global.game_progress = 2;
...And so on.
Pseudocode example of a multi-quest progress tracking system:
global.quests = {};
function Quest (_name, desc = "") constructor {
name = _name;
stage = 0;
desc = desc;
hint_text = [];
}
function CreateQuest(quest_id,quest_name,desc){
global.quests[$ quest_id] = new Quest(quest_name,desc);
}
function SetStageHint(quest_id,stage,text){
global.quests[$ quest_id].hint_text[stage] = text;
}
CreateQuest("MainQuest","Escape the room!","Find a way to get out of the room!");
SetStageHint("MainQuest",0,"Ask around about a key for the door");
SetStageHint("MainQuest",1,"Bob said there is a key on the table in the living room. I should go check.");
SetStageHint("MainQuest",2,"I've found the key for the door. I should go open it.");
There are about a million ways to write this, so it really comes down to what is most readable and comfortable for you, in terms of data-entry.
Thank you, I'm sure this will help me a lot. But where am I supposed to write this code in the event create or step of an object, or in a scr, or somewhere else?
None of that code is intended for you to put anywhere. It is intended to be an example of how you might structure quest data.
I don't know what the needs of your game actually are. You might need the more elaborate system, you might get by just using a simple number to track progress.
Whatever system you use, you would initialize whatever globals you are storing your quests in when the game starts. You could do that in the create event of an initialization object. You could also do it in a script file -- wherever your game is initializing global stuff which gets set up once when the game starts.
You would check the quest stage from various objects and various events. Same for setting the quest stage as the player progresses through the game.