Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Cycle through dialogue with button press


kftb
 Share

Recommended Posts

Hi!

I am currently trying to program a tiny game where players can talk to NPCs (initiated when closeby and Spacebar is pressed), and then cycle through the dialogue by pressing Spacebar again for each entry. 

The dialogue sits in a JSON file. My problem: I cannot cycle through the dialogue piece by piece because in the moment I hit spacebar, it runs through all dialogue options triggered by a single spacebar press. 

Code: 

 

	var convo_gatekeeper = "1000";
	var convo_gatekeeper_next = null;

	initializeDialogue: function(object) {
		if (this.checkDialogueRequirements(object)) {
			spacebar.onDown.add(function() {  this.listenerDialogue(object);}, this);
		}

	},

	listenerDialogue: function() {

		convo_gatekeeper = this.startTalking();
	},

	startTalking: function ()  {
		speech = game.cache.getJSON('dialogue');

		convo = speech["conversations"]["Gatekeeper"]["elements"][convo_gatekeeper]["text"];
		convo_gatekeeper_next = speech["conversations"]["Gatekeeper"]["elements"][convo_gatekeeper]["followups"];

		return convo_gatekeeper_next;

    },

 

It works when I change it to 

 

	initializeDialogue: function(object) {
		if (this.checkDialogueRequirements(object)) {
			spacebar.onDown.add(this.listenerDialogue, this);
		}

But then it does not care about my initial check "checkDialogueRequirements" and just triggers whenever I hit the spacebar. In addition, I want to pass an object to the functions (which is not specified further in the code snippet) which only works with number 1. I am close to going insane because I cannot figure out what is going wrong. 

 

Any help would be much appreciated!

 

Thanks!

Link to comment
Share on other sites

Because between this getting approved and losing my mental sanity, I digged deeper and finally found the solution (I hope). I figured that to catch the onDown-event it had to be in the update loop, but realized now that it doesnt have to be. That was also the reason it kept triggering of course. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...