How do I lock levels with storyboard

I would have used a:

timer.performWithDelay(1000, function() text1:removeSelf(); text1 = nil; end)  

Instead of a transition.to since you’re not actually transitioning anything. Now if you were fading it out by changing the alpha from 1 to 0, then I would do what you did:

trasnition.to(text1, {time=1000, alpha=0.0, onComplete=function() text1:removeSelf(); text1 = nil; end})  

But as I posted above, double clicking should do nothing because text1 has NO eventListeners on it *** in the code you’ve posted above ***

So something else has to be responding to your clicks. If your double click is supposed to change scenes, then perhaps you’re not adding text1 to the scene’s display group/view. If you don’t then that display object becomes part of the overall game’s display. Any thing you DO NOT put into a scene’s group stays on the screen and storyboard won’t remove it when it changes scenes.

Make sure to do a:

  
group:insert(text1)  
  

if you want storyboard to manage removing it when it changes scenes. [import]uid: 19626 topic_id: 25923 reply_id: 108948[/import]

the code works as it won’t get stuck now. the problem is if i double click the item i get a error.

Runtime error
…emanouel/CoronaProjects/HH/scene1.lua:27: attempt to index upvalue ‘text1’ (a nil value)
stack traceback:
[C]: ?
…emanouel/CoronaProjects/HH/scene1.lua:27: in function <…emanouel>
(tail call): ?
?: in function <?:1184>
?: in function <?:226>

<br>---------------------------------------------------------------------------------<br>-- Room 1<br>---------------------------------------------------------------------------------<br>local storyboard = require( "storyboard" )<br>local scene = storyboard.newScene()<br>---------------------------------------------------------------------------------<br>-- BEGINNING OF YOUR IMPLEMENTATION<br>---------------------------------------------------------------------------------<br>local background, room2, blackKey, blackdoorlocked, text1 <br><br>-- Touch event listener for background image<br>local function gotoRoom2( self, event )<br> if event.phase == "began" then<br> <br> storyboard.gotoScene( "scene2", "fade", 400 )<br> <br> return true<br> end<br>end<br><br>local function door1locked( self, event )<br> if event.phase == "began" then <br> print ("clicked on Door Locked")<br> text1 = display.newText( "Door is Locked, the key should be near by", 0, 245, native.systemFontBold, 20 )<br> text1:setTextColor( 255 ) <br> --transition.to(text1, {time=1000, onComplete = function() display.remove(text1) end})<br> transition.to(text1, {time=1000, alpha=0.0, onComplete=function() text1:removeSelf(); text1 = nil; end})<br> return true <br> end<br>end<br><br>local function foundBlackKey( self, event )<br> if event.phase == "began" then<br> print ("Door 1 Is Now Open")<br> blackdoorlocked.isVisible = false<br> blackKey.isVisible = false<br> storyboard.settings.keyFound[1] = true<br> storyboard.settings.doorUnLocked[1] = true<br> storyboard.saveTable(storyboard.settings, "settings.json")<br> return true<br> end<br>end<br><br>-- Called when the scene's view does not exist:<br>function scene:createScene( event )<br> local screenGroup = self.view<br> <br> background = display.newImage( "assets/graphics/Room1.png", 0, 0 )<br> screenGroup:insert( background )<br> <br> room2 = display.newImage( "assets/graphics/gotoRoom2.png", 175, 0 )<br> screenGroup:insert( room2 )<br> <br> room2.touch = gotoRoom2<br> <br> blackKey = display.newImage( "assets/graphics/BlackKey.png", 400, 250 )<br> screenGroup:insert( blackKey )<br> blackKey.touch = foundBlackKey<br> blackKey.isVisible = true<br> <br> blackdoorlocked = display.newImage( "assets/graphics/BlackDoorLocked.png", 175, 0 )<br> screenGroup:insert( blackdoorlocked )<br> blackdoorlocked.touch = door1locked<br> blackdoorlocked.isVisible = true<br> <br>if storyboard.settings.doorUnLocked[1] == true then<br> -- the level is locked<br> print ("DOOR 1 IS UNLOCKED")<br> blackdoorlocked.isVisible = false<br>else<br> -- the level is unlocked<br> print ("DOOR 1 IS LOCKED")<br> blackdoorlocked.isVisible = true<br>end <br><br>if storyboard.settings.keyFound[1] == true then<br> print ("THE KEY WAS FOUND")<br> blackKey.isVisible = false<br>else<br> print ("THE KEY WAS NOT FOUND")<br> blackKey.isVisible = true<br>end <br><br> print( "\n1: createScene event")<br>end<br><br>-- Called immediately after scene has moved onscreen:<br>function scene:enterScene( event )<br> local group = self.view <br> print( "1: enterScene event" )<br> <br> local lastScene = storyboard.getPrevious()<br> <br> print( "last scene was:", lastScene ) -- output: last scene name<br> <br> -- Update Lua memory text display<br> room2:addEventListener( "touch", room2 )<br> blackKey:addEventListener( "touch", blackKey )<br> blackdoorlocked:addEventListener( "touch", blackdoorlocked )<br><br>end<br><br>-- Called when scene is about to move offscreen:<br>function scene:exitScene( event )<br> local group = self.view <br> print( "1: exitScene event" )<br> <br> -- remove touch listener for image<br> room2:removeEventListener( "touch", room2 )<br> blackKey:removeEventListener( "touch", blackKey )<br> blackdoorlocked:removeEventListener( "touch", blackdoorlocked )<br>end<br>-- Called prior to the removal of scene's "view" (display group)<br>function scene:destroyScene( event )<br> local group = self.view<br> print( "((destroying scene 1's view))" )<br>end<br><br>---------------------------------------------------------------------------------<br>-- END OF YOUR IMPLEMENTATION<br>---------------------------------------------------------------------------------<br><br>-- "createScene" event is dispatched if scene's view does not exist<br>scene:addEventListener( "createScene", scene )<br><br>-- "enterScene" event is dispatched whenever scene transition has finished<br>scene:addEventListener( "enterScene", scene )<br><br>-- "exitScene" event is dispatched before next scene's transition begins<br>scene:addEventListener( "exitScene", scene )<br><br>-- "destroyScene" event is dispatched before view is unloaded, which can be<br>-- automatically unloaded in low memory situations, or explicitly via a call to<br>-- storyboard.purgeScene() or storyboard.removeScene().<br>scene:addEventListener( "destroyScene", scene )<br><br>---------------------------------------------------------------------------------<br><br>return scene<br>

so im assuming i need to put event listeners for the text >?? i have event listeners for the object as seem in the code above. [import]uid: 17701 topic_id: 25923 reply_id: 108953[/import] </…emanouel>

UPDATE:

i changed line 27 to

transition.to(text1, {time=2000, alpha=0.0, onComplete=function() end})

it seems to fix the issue. i guess text1 never had a value ? am i correct ??? [import]uid: 17701 topic_id: 25923 reply_id: 108954[/import]

I don’t see anything wrong with that code. Maybe someone else could help out.

By not removing text1 you’re creating a memory leak.

[import]uid: 19626 topic_id: 25923 reply_id: 108960[/import]

when i left the text1 = nil i get errors. so I’m not sure what to do

Runtime error
…emanouel/CoronaProjects/HH/scene1.lua:27: attempt to index upvalue ‘text1’ (a nil value)
stack traceback:
[C]: ?
…emanouel/CoronaProjects/HH/scene1.lua:27: in function <…emanouel>
(tail call): ?
?: in function <?:1184>
?: in function <?:226>

it has to do with line 27 and I’m not sure what index up value means [import]uid: 17701 topic_id: 25923 reply_id: 108966[/import] </…emanouel>

Rob,

just wondering how i would store the current scene thats I’m currently in into the game settings.

i assume I’m only able to save numeric values as well as true / false statements. i tried storing scene 1 but it would not work.

any suggestions ?? [import]uid: 17701 topic_id: 25923 reply_id: 109302[/import]

Rob,

just wondering how i would store the current scene thats I’m currently in into the game settings.

i assume I’m only able to save numeric values as well as true / false statements. i tried storing scene 1 but it would not work.

any suggestions ?? [import]uid: 17701 topic_id: 25923 reply_id: 109303[/import]

You can store: strings, numbers and true/false values. I’m guessing you could store display objects, but you will use an enormous amount of storage and it really doesn’t do anything.
You need to store just enough information to restore the game to the saved state.

Lets say your building Space Invaders. You don’t need to save the position of the alien space ship, the bullet positions on the screen, the shield damage or even the position of the player’s ship because you are only going to save things at “save points”, like at the end of a successful level.

Since you are building what appears to be an adventure game, you probably should save any items the player has in their inventory. If there are objects that have to be moved or placed in certain points, you could simply store a true/false if the items is in its original place or in its destination place. But you don’t need to save the actual object. You can recreate that in your createScene function.
[import]uid: 19626 topic_id: 25923 reply_id: 109304[/import]

Rob,

i don’t want to store any objects , just need a way to go back to the last scene you were on when quitting the game.

thats correct its a point and click adventure game. so when I’m in room 5 and then quit. i want to start off back in room 5. i already have the items being saved when picked up.
but I’m not sure how to go back to the last scene.

i was thinking of some how saving the value of the current scene into the settings at the quit mark, and then resuming

any ideas / suggestions ?? [import]uid: 17701 topic_id: 25923 reply_id: 109306[/import]

store the scene name as a string and in main.lua (or where ever you need to restore the scene) and do a storyboard.gotoScene(whatevervariableyousavedyourscenenamein)
[import]uid: 19626 topic_id: 25923 reply_id: 109307[/import]

im not sure what you mean by "store the scene name as a string " ?

I’m looking at http://developer.anscamobile.com/content/strings but now I’m even more confused.

UPDATE:

i tried

 storyboard.gotoScene(storyboard.settings.lastScene, "fade", 500) 

and in main.lua its setup as

storyboard.settings.lastScene = 10

the problem is that it starts to look for 10.lua. how do i go about placing the scene name before the 10 ??

i created a new file and copied my scene10.lua into it and saved it as 10.lua and it worked. the problem is that its a lot of work re coding all my files. there has to be a way to get the scene to be seen before the 10

any ideas? [import]uid: 17701 topic_id: 25923 reply_id: 109312[/import]

You have a lua file that you use to hold your scene. Lets say it’s called:

room5.lua

To get to room 5 you do:

storyboard.gotoScene(“room5”)

That “room5” is a string representing the scene name.
So you could do:

storyboard.settings.currentRoom = "room5"  
-- then your code to save the settings...  

then later you could do:

storyboard.gotoScene(storyboard.settings.currentRoom)  

but what might be more practical is to:

  
storyboard.settings.currentRoom = storyboard.getCurrentSceneName()  
  

instead of hard coding “room5”
[import]uid: 19626 topic_id: 25923 reply_id: 109369[/import]

Rob,

i also tried something similar but when i opened the setting files the scene1 never showed up so i assumed it did not store it.

storyboard.settings.currentRoom

wow thanks for the help, that work flawlessly :slight_smile:

when I’m working on a game over if players health = 0 , do i need to place that in the main.lua or is there a better way of implementing it ??

i would like to thank you for the help regarding the issues I’ve had with storyboard.

thanks [import]uid: 17701 topic_id: 25923 reply_id: 109437[/import]

Holy cow there is a lot going on in this thread.

Closely watching the interaction. I’m following along, new to storyboard API, and I used ego successfully on a per level basis right now. Each level saves the previous high score, and I put a reset button in there as well to reset the values.

I’m interested to see how this works out. Please post the working end sample code when it’s working :slight_smile:
:slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile:
ng [import]uid: 61600 topic_id: 25923 reply_id: 112386[/import]

Rob,

quick question

what if i wanted to reference two settings for example

for example settings.level[1] and [2] are true then…

storyboard.settings.levelLocked = {} -- make it a table  
storyboard.settings.levelLocked[1] = false -- assume level 1 is unlocked  
storyboard.settings.levelLocked[2] = true  
storyboard.settings.levelLocked[3] = true  
storyboard.settings.levelLocked[4] = true  
storyboard.settings.levelLocked[5] = true  
storyboard.settings.levelLocked[6] = true  
storyboard.settings.levelLocked = {false, true, true, false, true, true }  

just wondering if I’m able to use add, or should i do something different ?
[import]uid: 17701 topic_id: 25923 reply_id: 112979[/import]

if storyboard.settings.levelLocked[1] == true and storyboard.settings.levelLocked[2] == true then  
 -- if both have to be true, then do stuff here  
end  
  
-- or  
  
if storyboard.settings.levelLocked[1] == true or storyboard.settings.levelLocked[2] == true then  
 -- if either can be true, then do stuff here  
end  
  

[import]uid: 19626 topic_id: 25923 reply_id: 112988[/import]

Rob,

thanks for the speedy response. now If i wanted to check four values would i have to do it like this

if storyboard.settings.levelLocked[1] == true and storyboard.settings.levelLocked[2] == true and storyboard.settings.levelLocked[3] == true and storyboard.settings.levelLocked[4] == true then  

i was wondering if there was a simpler way like

if storyboard.settings.levelLocked[1, 2, 3, 4] [import]uid: 17701 topic_id: 25923 reply_id: 113116[/import]

No, you can’t do the later. The first with all the “ands” is too complex.

This is where you might want to use a loop:

  
local levelsAreLocked = false  
for i = 1, #storyboard.settings.levelLocked do  
 if storyboard.settings.levelLocked[i] then levelsAreLocked = true end  
end  
  
if levelsAreLocked then  
 -- do your locked code here  
end  
  

[import]uid: 19626 topic_id: 25923 reply_id: 113122[/import]