Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

back to previous scene (with storyboard)
Started by tore24 Dec 30 2012 03:55 AM

- - - - -
39 replies to this topic
[TOPIC CONTROLS]
Page 2 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

tore24

[GLOBAL: userInfoPane.html]
tore24
  • Contributor

  • 103 posts
  • Corona SDK

but if I have a variable life and I want when I return back to the initial state lives (3 lives) how do I do? Currently in my real project I still ticking 0 life.
uid: 98258 topic_id: 34428 reply_id: 137033


[TOPIC: post.html]
#27

tore24

[GLOBAL: userInfoPane.html]
tore24
  • Contributor

  • 103 posts
  • Corona SDK

Resume:

game.lua

lives = 3

when my sprite dead, is 0 live = gameover.lua

I press restart and go to game.lua, but in game.lua remains 0 lives and not 3 lives (Not restart)

This is my grand problem :(
uid: 98258 topic_id: 34428 reply_id: 137034


[TOPIC: post.html]
#28

Tim @ Playful Media

[GLOBAL: userInfoPane.html]
Tim @ Playful Media
  • Observer

  • 21 posts
  • Corona SDK

aitor.10794 - You need to set it back to 3 when ever is appropriate. Thus if you have a reset button then you would set this variable back to 3 and pass it back or save it back to the Storyboard variable you are using or if you want it always reset to 3 when you restart the game then in your main.lua file you would set it there and pass it.
uid: 190375 topic_id: 34428 reply_id: 137035


[TOPIC: post.html]
#29

tore24

[GLOBAL: userInfoPane.html]
tore24
  • Contributor

  • 103 posts
  • Corona SDK

I reset in case the variable "Lives". Reiniciar_partida function included in the following. In gameober.lua

local function reiniciar_partida ()display.remove(nickText)display.remove(background)display.remove(botonmenu)display.remove(botonenviar)display.remove(scoreText)lives = 3score = 0    storyboard.gotoScene( "game", "slideLeft", 800 )end
uid: 98258 topic_id: 34428 reply_id: 137036


[TOPIC: post.html]
#30

tore24

[GLOBAL: userInfoPane.html]
tore24
  • Contributor

  • 103 posts
  • Corona SDK

but still not working.... :'(
uid: 98258 topic_id: 34428 reply_id: 137037


[TOPIC: post.html]
#31

Tim @ Playful Media

[GLOBAL: userInfoPane.html]
Tim @ Playful Media
  • Observer

  • 21 posts
  • Corona SDK

Well when and how are you calling this function? How are you passing the value of lives back to the start? Is this a global variable? If not then you are just setting lives to 3 locally and it will not persist.

You need to pass this value back to the start one way or the other. Either through Storyboard or through a global variable. Obviously using locals and passing values is better than a bunch of global variables.
uid: 190375 topic_id: 34428 reply_id: 137040


[TOPIC: post.html]
#32

tore24

[GLOBAL: userInfoPane.html]
tore24
  • Contributor

  • 103 posts
  • Corona SDK

Ok, this function is called from a addEventListener. The variable is global score but just now I realize that always happens with value 0 (even really the value 4 for example).
So how I can pass the variable to gameover.lua can score reset after? (Like the variable lives)
What would be the correct way? (as I see it with a global variable either)
uid: 98258 topic_id: 34428 reply_id: 137042


[TOPIC: post.html]
#33

tore24

[GLOBAL: userInfoPane.html]
tore24
  • Contributor

  • 103 posts
  • Corona SDK

really involves passing score to gameover.lua variable and then press the button when restart set the variable to 0 and the score to 3 lives.
uid: 98258 topic_id: 34428 reply_id: 137043


[TOPIC: post.html]
#34

Tim @ Playful Media

[GLOBAL: userInfoPane.html]
Tim @ Playful Media
  • Observer

  • 21 posts
  • Corona SDK

Does gameover.lua use the storyboard system?

When something happens to trigger game over then I assume you go to a scene called "gameover"? Then in game over you will show a button to restart or something? So there you could set the variables for score to 0 and lives to 3 and go to game start (scene1?).

Thus you just need to set the variables as shown in the link I posted above for passing variables, for example...

in main.lua

storyboard.state = {}
storyboard.state.score = 0
storyboard.state.lives = 3

in gameover.lua

storyboard.state.score = 0
storyboard.state.lives = 3
storyboard.gotoScene( "game", "slideLeft", 800 )
uid: 190375 topic_id: 34428 reply_id: 137044


[TOPIC: post.html]
#35

tore24

[GLOBAL: userInfoPane.html]
tore24
  • Contributor

  • 103 posts
  • Corona SDK

It is exactly as you think.
Then on this basis. I do the following in game.lua?
_G. score = Storyboard.state.score
and
Local lives = storyboard.state.lives???

I apply what I've said in my variables? (I'm a bit awkward in this respect)
Thanks for your help!
uid: 98258 topic_id: 34428 reply_id: 137046


[TOPIC: post.html]
#36

Tim @ Playful Media

[GLOBAL: userInfoPane.html]
Tim @ Playful Media
  • Observer

  • 21 posts
  • Corona SDK

Assuming game.lua is a storyboard scene you could access the lives as such:
local lives = Storyboard.state.lives
local score = Storyboard.state.score

During some action in game.lua

lives = lives - 1
score = score + 10
or whatever....

Then before you transition to another scene make sure to save these back:

Storyboard.state.lives = lives
... etc.
uid: 190375 topic_id: 34428 reply_id: 137049


[TOPIC: post.html]
#37

tore24

[GLOBAL: userInfoPane.html]
tore24
  • Contributor

  • 103 posts
  • Corona SDK

I did a print and tells me it's score is nil. Anyway tomorrow I will write back the 1600 lines of code because right now I have a mess .... Anyway it may be that nil?
uid: 98258 topic_id: 34428 reply_id: 137051


[TOPIC: post.html]
#38

tore24

[GLOBAL: userInfoPane.html]
tore24
  • Contributor

  • 103 posts
  • Corona SDK

The print was in gameover.lua
uid: 98258 topic_id: 34428 reply_id: 137052


[TOPIC: post.html]
#39

Tim @ Playful Media

[GLOBAL: userInfoPane.html]
Tim @ Playful Media
  • Observer

  • 21 posts
  • Corona SDK

I think you need to stop copy and pasting code and just understand how to write it yourself first. How can you have 1600 lines of code and yet not understand the basics of variable scope?

You seem to be ahead of yourself. I love to help but I'm not going to write the game for you.
uid: 190375 topic_id: 34428 reply_id: 137053


[TOPIC: post.html]
#40

tore24

[GLOBAL: userInfoPane.html]
tore24
  • Contributor

  • 103 posts
  • Corona SDK

apology. I explain wrong, sometimes I have trouble enough English to express myself rather well. I meant that I did not understand what the storyboard step variable from one scene to another, I know that the global can and does until yesterday I did well, what happens is that both modify the code to finish rolling. 1600 lines are just so many features that I returned to copy the same code (saving). Anyway, it's true that I'm starting and not yet mastered this language very well. There are things that escape me and I try to find a complete online course but I find it difficult to find, only found the reference guide and little else. Tomorrow rewrite the code from scratch more than anything to get it right from the start and not so wrong. Thanks anyway to you and to rob. Coming to schedule picking fluency so these days if I have a problem I write (I hope not to have them!).

Thanks! ;)
uid: 98258 topic_id: 34428 reply_id: 137060



[topic_controls]
Page 2 of 2 1 2
 
[/topic_controls]