Creating a tutorial framework

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Ducktor Cid
Prole
Posts: 18
Joined: Wed Oct 05, 2016 8:08 pm

Creating a tutorial framework

Post by Ducktor Cid »

With the game I'm creating, I'm at the point where I've got everything down(levels, menu, gameplay etc) but now I want to add a tutorial system to some levels.

Currently, I do it like this:
I create a separate .lua file for each level
inside each level file I have this(this is from the first level):

Code: Select all

	
	Level.textObjects={
		{["Text"]="Welcome to Hex!",["t"]=4},
		{["Text"]="The main premise of this game is to capture all of the AI's hexagons",["t"]=3},
		{["Text"]="To do this, hover over one of your(shown by the '1') fire element hexagons (the red ones)",["t"]=5},
		{["Text"]="Hopefully, you see that two earth element hexagons (brown) were highlighted below your fire hexagon(all capturable neighbors are highlighted on-hover). Click now to take over them.",["t"]=7},
		{["Text"]="You'll see you took over the hexagon and then the AI had a turn. Now, using what I told you, finish the level!",["t"]=4}
	}

But it's very basic (it just displays text for ["t"] amount of time before displaying the next text). What I want to do is make it so the tutorial is paused until the player does something (for example, on the third text object it tells you to hover over your hexagons. I want it so it doesn't continue to the next part UNTIL you hover over one of your hexagons). Another action I want to be able to do is not continue until the player clicks on one of their hexagons (as told to the player on the 4th text object)

This is how I use the textObjects table in main.lua(I'm using hump.timer I believe):

Code: Select all

	
	TutorialTimer:script(function(w)	
		if Level.textObjects then
			for index, textObject in pairs(Level.textObjects) do
				local text=textObject["Text"]
				local timeUp=textObject["t"]
				table.insert(Level.textObjectsOnScreen,{["text"]=text,x=20,y=50}) -- Level.textObjectsOnScreen just keeps ahold of the text dialogue information for love.draw
				w(timeUp)
				table.remove(Level.textObjectsOnScreen,1)
			end
		end
	end)	
Anyone got any idea on how I can implement this?
josip
Prole
Posts: 21
Joined: Tue Oct 03, 2017 1:55 pm

Re: Creating a tutorial framework

Post by josip »

Usually this is done with event system. This approach scales well and it's easy to add to existing code.

As you update your game state, you fire off events whenever some action occur (user hovers over hex, turn ends, game over...). The game state update doesn't know anything about tutorial, it just fires off events blindly to anyone listening.

Your tutorial code subscribes to events that should trigger tutorial messages. Once message is triggered and displayed, tutoral can unsubscribe from that event type.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests