Can't make sence of scenes...what am i doing wrong?

I am trying to make a card game… I am creating a scene, making the background,and adding an image where when the player touches he/she will be transfered to the next scene.

local storyboard = require(“storyboard”)
local singlePlayer = storyboard.newScene()

local card1,card2,card3

function singlePlayer:createScene(event )
    local group = self.view
    – body
    local bg = display.newImage(“bg.png”)
    bg.x = 100 ; bg.y = 50
    group:insert(bg)
end

function singlePlayer:enterScene( event )
    local group = self.view
    local count = math.random(3)

    if(count == 1) then
        card1 = display.newImage(“attack.png”)
        card1.x = 50 ; card1.y = 150
        group:insert(card1)
    else
        card1 = display.newImage(“ability.png”)
        card1.x = 50 ; card1.y = 150
        group:insert(card1)
    end

    function card1:touch(event )
        print(“ok”)
        if(event.phase == “ended”) then
            storyboard.gotoScene(“opponent_scene”)
        else
        end
        – body
    end

    card1:addEventListener(“touch”,card1)

    – body
end

function singlePlayer:exitScene(event)
    local group = self.view
    card1:removeEventListener(“touch”,card1)
end

singlePlayer:addEventListener(“createScene”,singlePlayer)
singlePlayer:addEventListener(“enterScene”,singlePlayer)
singlePlayer:addEventListener(“exitScene”,singlePlayer)

return singlePlayer

local storyboard = require(“storyboard”)
local opponent_scene = storyboard.newScene()

function opponent_scene:createScene(event )
    print(“opponent_scene created”)
    – body
end

function opponent_scene:enterScene(event )
    print(“opponent_scene enter”)
    local group  = self.view
    storyboard.removeScene(“judge”)
    local text = display.newText(“Opponent’s turn”,150,200)
    storyboard.gotoScene(“judge”)
    – body
end

function opponent_scene:exitScene(event )
    – body
    local group = self.view

end

opponent_scene:addEventListener(“createScene”,opponent_scene)
opponent_scene:addEventListener(“enterScene”,opponent_scene)
opponent_scene:addEventListener(“exitScene”,opponent_scene)

return opponent_scene

local storyboard = require(“storyboard”)
local judge = storyboard.newScene()

function judge:createScene(event )
    local group = self.view
    local bg = display.newImage(“destiny.png”)
    storyboard.removeScene(“opponent_scene”)
    storyboard.gotoScene(“singlePlayer”)
    – body
end

judge:addEventListener(“createScene”,judge)

return judge

Will anyone explain to me what is going on with these scenes?

All i want is to make the game wait for the player’s input (touching of the card)

Please please someone hlp

I’m presuming this is two files joined together ? Corona Scenes are really designed for one scene = one file.

Assuming that’s not it, what actually happens when you try to run it ? 

You have several things.  In the judge scene, you never add  your bg to your group, so it will sit on top of everything else.  Next in your opponent_scene:enterScene() there is no interactivity, it jumps straight to judge.

While you can technically put multiple scene’s in one file and I’m sure there are some rare use cases where this is helpful, it’s really best to have one scene in one file as Paul said.  

Rob

These are 3 files, sorry that i didn’t make it clear…

Also i have added the background in the judge scene…

Now what i get is…

first run, background appears and the image appears.

clicking on the image, i get the text from the opponent scene, (the background is still there)

after that i get the background and the random image from the player file.

I click on the image a couple of more times and i get a black screen with only the text from the opponent scene.

(what i want to do is, to have the game wait for the player’s input and then briefly flash the opponent’s text and then go to judge for some error checking and again go to the player scene and wait for another input)

(these are not the files that i am using in my project, these files are made only to see how scenes work so i could fix my normal files)

(I hope i made sense)

If you get a black screen, you likely crashed…  You need to look at your console log and see what’s going on.  If you don’t know how to do that, then this tutorial will be of help:

http://coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

As far as the background staying there are you adding your objects to the scene’s “group”?

Perhaps you could repost your latest code?

Rob

now it just stays in the enter scene of the 2nd module… Rob said something about not being interactivity in there… what do you mean? (i don’t want to do any actions there… i want it to go through opponent scene through judge and then go to single player and wait for the player to touch on the image)

i will share the code i have in my original project… those were file i made just to try to make sense of scenes…

sorry for the length…

local storyboard = require(“storyboard”)
local singlePlayer2 = storyboard.newScene()
local twisted = require(“TF”)
local warwick = require(“Warwick”)
local global_data = require(“global_data”)

–forward declaration
local player_img,opponent,opponent_img,hero

–Find which character the player chose
    local path = system.pathForFile(“Player.txt”,system.DocumentsDirectory)
    local file = io.open(path,“r”)
    local player = file:read("*a")
    io.close(file)
    file = nil

    if (player == “TF”) then --when reading the file for player’s choise, IF the player chose TF, single player will start as follows
            hero = 1
            
    else
    --if the player chose warwick, single player will start as follows…
            hero = 2
    end

    local randNum = math.random(2) --creating an opponent randomly
        
    if(randNum == 1) then
        opponent = 1
        

    else
        opponent = 2
                
    end

function singlePlayer2:createScene( event )
    local group = self.view

    local background = display.newImage(“Treeline.png”)
    background.x = 150 ; background.y = 240
    group:insert(background)

    
            – body

        local info =
        {
            text = "Round: "…global_data.round,
            x = 150,
            y = 150,
            font = native.systemFontBold ,
            fontSize = 20
        }

        local info_text = display.newText(info)
        group:insert(info_text)
    
    end

    function singlePlayer2:enterScene(event )
        local group = self.view
        -------------------card creation----------------------------------------------------------------
        
        


        function card1:touch( event )
            if(global_data.attack_type == 1) then
                local damage = twisted.basick_attack()
                global_data.opponentHealth = opponent.getDamage(damage)
            elseif(global_data.attack_type == 2) then

                global_data.opponentHealth = opponent.getDamage(twisted.wild_cards(0))
            elseif(global_data.attack_type == 3) then
                --opponent.getDamage(twisted.pick_card(0))
            elseif(global_data.attack_type == 4) then
                global_data.opponentHealth = opponent.getDamage(twisted.stack_deck(0))
            elseif(global_data.attack_type == 5) then
                twisted.ulti(0)
            end

            storyboard.gotoScene(“opponent_scene”)
        end

    card1:addEventListener(“touch”,card1)
        – body
    end

    function singlePlayer2:willEnterScene( event )
        local group = self.view
        local card1_count = math.random(5)

    if(hero == 1 ) then
            twisted = twisted.new()
            player_img = twisted.setPositionForImage(50,470)
            global_data.playerHealth = twisted.getCurHealth()
            global_data.playerMana = twisted.getCurMana()    
        else
            warwick = Warwick.new()
            player_img = warwick.setPositionForImage(50,470)
    end

    if(opponent == 1) then
        opponent = twisted.new()
        opponent_img = twisted.setPositionForImage(250,50)
        global_data.opponentMana = twisted.getCurMana()
        global_data.opponentHealth = twisted.getCurHealth()
    else
        opponent = Warwick.new()
        opponent_img =warwick.setPositionForImage(250,50)
        global_data.opponentHealth = Warwick.getCurHealth()
        global_data.opponentMana = Warwick.getCurMana()
    end

    group:insert(player_img)
    group:insert(opponent_img)
    local playerInfo_Health =
    {
                text = "HP = "…global_data.playerHealth,
                x = 160,
                y = 420,
                font= native.systemFontBold,
                fontSize = 20
            }

            local hp = display.newText(playerInfo_Health)
            group:insert(hp)

            local playerInfo_Mana =
            {
                text = "Mana = "…global_data.playerMana,
                x = 170,
                y = 455,
                font = native.systemFontBold,
                fontSize = 20
            }

            local mana = display.newText(playerInfo_Mana)
            group:insert(mana)    

            local opponentInfo_health =
            {
                text = “HP =”…global_data.opponentHealth,
                x = 70,
                y = 50,
                font = native.systemFontBold,
                fontSize = 20
            }

            opponent_text_HP = display.newText(opponentInfo_health)
            group:insert(opponent_text_HP)

            local opponentInfo_Mana =
        {
            text = "Mana = "…global_data.opponentMana,
            x = 85,
            y = 75,
            font = native.systemFontBold,
            fontSize = 20
        }

            opponent_text_MANA = display.newText(opponentInfo_Mana)
            group:insert(opponent_text_MANA)

        if(card1_count == 1) then
            card1 = display.newImage(“attack.png”)
            card1.x = 50 ; card1.y = 240
            global_data.attack_type2 = 1
        elseif(card1_count == 2) then
            card1 = display.newImage(“wild_cards.png”)
            card1.x = 50 ; card1.y = 240
            global_data.attack_type2 = 2
        elseif(card1_count == 3) then
            card1 = display.newImage(“pick_a_card.png”)
            card1.x = 50 ; card1.y = 240
            global_data.attack_type2 = 3
        elseif(card1_count == 4) then
            card1 = display.newImage(“stacked_deck.png”)
            card1.x = 50 ; card1.y = 240
            global_data.attack_type2 = 4
        elseif(card1_count == 5) then
            card1 = display.newImage(“destiny.png”)
            card1.x = 50 ; card1.y = 240
            global_data.attack_type2 = 5
        end

        group:insert(card1)

        if(card1_count ~= 5) then
            card2_count = math.random(5)
        else
            card2_count = math.random(4)
        end

        if(card2_count == 1) then
            card2 = display.newImage(“attack.png”)
            card2.x = 150 ; card2.y = 240
            global_data.attack_type2 = 1
        elseif(card2_count == 2) then
            card2 = display.newImage(“wild_cards.png”)
            card2.x = 150 ; card2.y = 240
            global_data.attack_type2 = 2
        elseif(card2_count == 3) then
            card2 = display.newImage(“pick_a_card.png”)
            card2.x = 150 ; card2.y = 240
            global_data.attack_type2 = 3
        elseif(card2_count == 4) then
            card2 = display.newImage(“stacked_deck.png”)
            card2.x = 150 ; card2.y = 240
            global_data.attack_type2 = 4
        elseif(card2_count == 5) then
            card2 = display.newImage(“destiny.png”)
            card2.x = 150 ; card2.y = 240
            global_data.attack_type2 = 5
        end

        group:insert(card2)

        if(card1_count ~= 5 and card2_count ~= 5) then
            card3_count = math.random(5)
        else
            card3_count = math.random(4)
        end

        if(card3_count == 1) then
            card3 = display.newImage(“attack.png”)
            card3.x = 250 ; card3.y = 240
            global_data.attack_type3 = 1
        elseif(card3_count == 2) then
            card3 = display.newImage(“wild_cards.png”)
            card3.x = 250 ; card3.y = 240
            global_data.attack_type3 = 2
        elseif(card3_count == 3) then
            card3 = display.newImage(“pick_a_card.png”)
            card3.x = 250 ; card3.y = 240
            global_data.attack_type3 = 3
        elseif(card3_count == 4) then
            card3 = display.newImage(“stacked_deck.png”)
            card3.x = 250 ; card3.y = 240
            global_data.attack_type3 = 4
        elseif(card3_count == 5) then
            card3 = display.newImage(“destiny.png”)
            card3.x = 250 ; card3.y = 240
            global_data.attack_type3 = 5
        end
        
        group:insert(card3)

        
        – body
    end

    function singlePlayer2:exitScene(event )
        local group = self.view
        
        – body
    end

singlePlayer2:addEventListener(“createScene”,singlePlayer2)
singlePlayer2:addEventListener(“enterScene”,singlePlayer2)
singlePlayer2:addEventListener(“willEnterScene”,singlePlayer2)
singlePlayer2:addEventListener(“exitScene”,singlePlayer2)

return singlePlayer2
 

------------opponent scene----------------

local storyboard = require(“storyboard”)
local opponent_scene = storyboard.newScene()
local global_data = require(“global_data”)

local rand_attack = math.random(3)

function opponent_scene:createScene(event)

    print(“opponent create scene”)
    local group = self.view
    storyboard.purgeScene(“singlePlayer2”)
    local info =
    {
        text = “OPPONENT’S TURN!!”,
        x = 150,
        y = 250,
        font = native.systemFontBold,
        fontSize = 30

    }
    local info_text = display.newText(info)
    group:insert(info_text)

    

    if(rand_attack == 1) then
        print(“1”)
    elseif(rand_attack == 2) then
        print(“2”)
    else
        print(“3”)
    end    
    
end

function opponent_scene:enterScene( event )
    print(“opponent enter scene”)
    local group = self.view
    if(rand_attack == 1) then
        global_data.playerHealth = global_data.playerHealth - 30
        elseif(rand_attack == 2) then
            global_data.playerHealth = global_data.playerHealth - 50
        else
            global_data.playerHealth = global_data.playerHealth - 100
    end
    storyboard.gotoScene(“judge”)
end

function opponent_scene:exitScene( event )
    print(“opponent exit scene”)
    
    local group = self.view

    – body
end

opponent_scene:addEventListener(“createScene”,opponent_scene)
opponent_scene:addEventListener(“enterScene”,opponent_scene)
opponent_scene:addEventListener(“exitScene”,opponent_scene)

return opponent_scene

-----------------------judge scene

local storyboard = require(“storyboard”)
local judge = storyboard.newScene()
local global_data = require(“global_data”)
local twisted = require(“TF”)
local warwick = require(“Warwick”)

function judge:createScene(event)
    local group = self.view

    print("round = "…global_data.round)
    print("player hp = "…global_data.playerHealth)
    print("opponent hp = "…global_data.opponentHealth)
    storyboard.removeScene(“oppponent_scene”)
    global_data.round = global_data.round + 1

    if(global_data.opponentHealth > 0) then
        storyboard.gotoScene(“singlePlayer2”)
    else
        local grats =
        {
            text = “YOU WIN!!!”,
            x = 150,
            y = 250,
            font = native.systemFontBold,
            fontSize = 50
        }
        local text = display.newText(grats)
        group:insert(grats)
        
    end

end

judge:addEventListener(“createScene”,judge)

return judge


i am constantly changing single player… trying to make it work…

so far… i thought puting the player and the opponent outside the create scene (so as to be loaded once)

then in the enter scene i have my event listeners because i want them to be executed every time the scene appears…

as long as i don’t use storyboard.purgeAll() or storyboard.removeScene(“singlePlayer2”) it should not load the view again so it won’t go outside the create scene event right?

The idea behind scenes is that you go to one, do stuff, then go to another.  If you start in scene 1 and goto scene2 that immediately jumps to scene 3, what purpose is scene 2 doing?  In your opponent_scene your enter scene has this code:

function opponent\_scene:enterScene(event )     print("opponent\_scene enter")     local group  = self.view     storyboard.removeScene("judge")     local text = display.newText("Opponent's turn",150,200)     storyboard.gotoScene("judge")     -- body end

which you seem to have moved the display.newText to your createScene, which is proper.   But when this scene is shown on the screen, it immediately changes to the judge scene.  You will see this scene for 1/2 second.  Is that what you want?

I am sorry for the late reply, i found a different approach… Now it is working :slight_smile:

@Rob, yes i wanted the screen to appear just for a second… i thought 1/2 second is ok as well…

Yeah, you can display it for 0.0001 seconds if you want to :slight_smile: (actually the timer resolution probably won’t allow that …)

With Finite State Machines - what Composer and Storyboard basically are, you have to be fairly careful with re-entrant state changes - i.e. if your scene messages are called from the gotoScene() code, calling them again from one of their methods is a bit chancy.

It might work, but events can end up being fired in the wrong order, or not at all and it’s a bit vulnerable to Corona changing the implementation slightly. Developers occasionally do this for some reason or other while retaining the consistency of the APIs.

If you want an scene that is basically just an interim scene, then it is probably best to fire it on a timer from the event rather than directly from it.

I didn’t get to read about timers so i have no idea what i am talking about, but i would think that a timer is no good for me, because i want the transition to the next scene to happen when the user presses on a card.

What is the exact problem you are having?  I suspect the thread has gone off topic a big. 

Thanks

Rob

Well, you have to attach an event listener to the card.

@Rob, the problem i was having is that the card’s touch event handler was not waiting for user input, i moved it into the enter scene and i now use only two storyboard files, so when the user presses on a card it goes to the opponent.lua storyboard scene and then back to player scene (you were right having a third scene was not helping)

@paulscottrobson, i did, but i did that in the create scene… so it wasn’t working as expected…

I’m presuming this is two files joined together ? Corona Scenes are really designed for one scene = one file.

Assuming that’s not it, what actually happens when you try to run it ? 

You have several things.  In the judge scene, you never add  your bg to your group, so it will sit on top of everything else.  Next in your opponent_scene:enterScene() there is no interactivity, it jumps straight to judge.

While you can technically put multiple scene’s in one file and I’m sure there are some rare use cases where this is helpful, it’s really best to have one scene in one file as Paul said.  

Rob

These are 3 files, sorry that i didn’t make it clear…

Also i have added the background in the judge scene…

Now what i get is…

first run, background appears and the image appears.

clicking on the image, i get the text from the opponent scene, (the background is still there)

after that i get the background and the random image from the player file.

I click on the image a couple of more times and i get a black screen with only the text from the opponent scene.

(what i want to do is, to have the game wait for the player’s input and then briefly flash the opponent’s text and then go to judge for some error checking and again go to the player scene and wait for another input)

(these are not the files that i am using in my project, these files are made only to see how scenes work so i could fix my normal files)

(I hope i made sense)

If you get a black screen, you likely crashed…  You need to look at your console log and see what’s going on.  If you don’t know how to do that, then this tutorial will be of help:

http://coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

As far as the background staying there are you adding your objects to the scene’s “group”?

Perhaps you could repost your latest code?

Rob

now it just stays in the enter scene of the 2nd module… Rob said something about not being interactivity in there… what do you mean? (i don’t want to do any actions there… i want it to go through opponent scene through judge and then go to single player and wait for the player to touch on the image)

i will share the code i have in my original project… those were file i made just to try to make sense of scenes…

sorry for the length…

local storyboard = require(“storyboard”)
local singlePlayer2 = storyboard.newScene()
local twisted = require(“TF”)
local warwick = require(“Warwick”)
local global_data = require(“global_data”)

–forward declaration
local player_img,opponent,opponent_img,hero

–Find which character the player chose
    local path = system.pathForFile(“Player.txt”,system.DocumentsDirectory)
    local file = io.open(path,“r”)
    local player = file:read("*a")
    io.close(file)
    file = nil

    if (player == “TF”) then --when reading the file for player’s choise, IF the player chose TF, single player will start as follows
            hero = 1
            
    else
    --if the player chose warwick, single player will start as follows…
            hero = 2
    end

    local randNum = math.random(2) --creating an opponent randomly
        
    if(randNum == 1) then
        opponent = 1
        

    else
        opponent = 2
                
    end

function singlePlayer2:createScene( event )
    local group = self.view

    local background = display.newImage(“Treeline.png”)
    background.x = 150 ; background.y = 240
    group:insert(background)

    
            – body

        local info =
        {
            text = "Round: "…global_data.round,
            x = 150,
            y = 150,
            font = native.systemFontBold ,
            fontSize = 20
        }

        local info_text = display.newText(info)
        group:insert(info_text)
    
    end

    function singlePlayer2:enterScene(event )
        local group = self.view
        -------------------card creation----------------------------------------------------------------
        
        


        function card1:touch( event )
            if(global_data.attack_type == 1) then
                local damage = twisted.basick_attack()
                global_data.opponentHealth = opponent.getDamage(damage)
            elseif(global_data.attack_type == 2) then

                global_data.opponentHealth = opponent.getDamage(twisted.wild_cards(0))
            elseif(global_data.attack_type == 3) then
                --opponent.getDamage(twisted.pick_card(0))
            elseif(global_data.attack_type == 4) then
                global_data.opponentHealth = opponent.getDamage(twisted.stack_deck(0))
            elseif(global_data.attack_type == 5) then
                twisted.ulti(0)
            end

            storyboard.gotoScene(“opponent_scene”)
        end

    card1:addEventListener(“touch”,card1)
        – body
    end

    function singlePlayer2:willEnterScene( event )
        local group = self.view
        local card1_count = math.random(5)

    if(hero == 1 ) then
            twisted = twisted.new()
            player_img = twisted.setPositionForImage(50,470)
            global_data.playerHealth = twisted.getCurHealth()
            global_data.playerMana = twisted.getCurMana()    
        else
            warwick = Warwick.new()
            player_img = warwick.setPositionForImage(50,470)
    end

    if(opponent == 1) then
        opponent = twisted.new()
        opponent_img = twisted.setPositionForImage(250,50)
        global_data.opponentMana = twisted.getCurMana()
        global_data.opponentHealth = twisted.getCurHealth()
    else
        opponent = Warwick.new()
        opponent_img =warwick.setPositionForImage(250,50)
        global_data.opponentHealth = Warwick.getCurHealth()
        global_data.opponentMana = Warwick.getCurMana()
    end

    group:insert(player_img)
    group:insert(opponent_img)
    local playerInfo_Health =
    {
                text = "HP = "…global_data.playerHealth,
                x = 160,
                y = 420,
                font= native.systemFontBold,
                fontSize = 20
            }

            local hp = display.newText(playerInfo_Health)
            group:insert(hp)

            local playerInfo_Mana =
            {
                text = "Mana = "…global_data.playerMana,
                x = 170,
                y = 455,
                font = native.systemFontBold,
                fontSize = 20
            }

            local mana = display.newText(playerInfo_Mana)
            group:insert(mana)    

            local opponentInfo_health =
            {
                text = “HP =”…global_data.opponentHealth,
                x = 70,
                y = 50,
                font = native.systemFontBold,
                fontSize = 20
            }

            opponent_text_HP = display.newText(opponentInfo_health)
            group:insert(opponent_text_HP)

            local opponentInfo_Mana =
        {
            text = "Mana = "…global_data.opponentMana,
            x = 85,
            y = 75,
            font = native.systemFontBold,
            fontSize = 20
        }

            opponent_text_MANA = display.newText(opponentInfo_Mana)
            group:insert(opponent_text_MANA)

        if(card1_count == 1) then
            card1 = display.newImage(“attack.png”)
            card1.x = 50 ; card1.y = 240
            global_data.attack_type2 = 1
        elseif(card1_count == 2) then
            card1 = display.newImage(“wild_cards.png”)
            card1.x = 50 ; card1.y = 240
            global_data.attack_type2 = 2
        elseif(card1_count == 3) then
            card1 = display.newImage(“pick_a_card.png”)
            card1.x = 50 ; card1.y = 240
            global_data.attack_type2 = 3
        elseif(card1_count == 4) then
            card1 = display.newImage(“stacked_deck.png”)
            card1.x = 50 ; card1.y = 240
            global_data.attack_type2 = 4
        elseif(card1_count == 5) then
            card1 = display.newImage(“destiny.png”)
            card1.x = 50 ; card1.y = 240
            global_data.attack_type2 = 5
        end

        group:insert(card1)

        if(card1_count ~= 5) then
            card2_count = math.random(5)
        else
            card2_count = math.random(4)
        end

        if(card2_count == 1) then
            card2 = display.newImage(“attack.png”)
            card2.x = 150 ; card2.y = 240
            global_data.attack_type2 = 1
        elseif(card2_count == 2) then
            card2 = display.newImage(“wild_cards.png”)
            card2.x = 150 ; card2.y = 240
            global_data.attack_type2 = 2
        elseif(card2_count == 3) then
            card2 = display.newImage(“pick_a_card.png”)
            card2.x = 150 ; card2.y = 240
            global_data.attack_type2 = 3
        elseif(card2_count == 4) then
            card2 = display.newImage(“stacked_deck.png”)
            card2.x = 150 ; card2.y = 240
            global_data.attack_type2 = 4
        elseif(card2_count == 5) then
            card2 = display.newImage(“destiny.png”)
            card2.x = 150 ; card2.y = 240
            global_data.attack_type2 = 5
        end

        group:insert(card2)

        if(card1_count ~= 5 and card2_count ~= 5) then
            card3_count = math.random(5)
        else
            card3_count = math.random(4)
        end

        if(card3_count == 1) then
            card3 = display.newImage(“attack.png”)
            card3.x = 250 ; card3.y = 240
            global_data.attack_type3 = 1
        elseif(card3_count == 2) then
            card3 = display.newImage(“wild_cards.png”)
            card3.x = 250 ; card3.y = 240
            global_data.attack_type3 = 2
        elseif(card3_count == 3) then
            card3 = display.newImage(“pick_a_card.png”)
            card3.x = 250 ; card3.y = 240
            global_data.attack_type3 = 3
        elseif(card3_count == 4) then
            card3 = display.newImage(“stacked_deck.png”)
            card3.x = 250 ; card3.y = 240
            global_data.attack_type3 = 4
        elseif(card3_count == 5) then
            card3 = display.newImage(“destiny.png”)
            card3.x = 250 ; card3.y = 240
            global_data.attack_type3 = 5
        end
        
        group:insert(card3)

        
        – body
    end

    function singlePlayer2:exitScene(event )
        local group = self.view
        
        – body
    end

singlePlayer2:addEventListener(“createScene”,singlePlayer2)
singlePlayer2:addEventListener(“enterScene”,singlePlayer2)
singlePlayer2:addEventListener(“willEnterScene”,singlePlayer2)
singlePlayer2:addEventListener(“exitScene”,singlePlayer2)

return singlePlayer2
 

------------opponent scene----------------

local storyboard = require(“storyboard”)
local opponent_scene = storyboard.newScene()
local global_data = require(“global_data”)

local rand_attack = math.random(3)

function opponent_scene:createScene(event)

    print(“opponent create scene”)
    local group = self.view
    storyboard.purgeScene(“singlePlayer2”)
    local info =
    {
        text = “OPPONENT’S TURN!!”,
        x = 150,
        y = 250,
        font = native.systemFontBold,
        fontSize = 30

    }
    local info_text = display.newText(info)
    group:insert(info_text)

    

    if(rand_attack == 1) then
        print(“1”)
    elseif(rand_attack == 2) then
        print(“2”)
    else
        print(“3”)
    end    
    
end

function opponent_scene:enterScene( event )
    print(“opponent enter scene”)
    local group = self.view
    if(rand_attack == 1) then
        global_data.playerHealth = global_data.playerHealth - 30
        elseif(rand_attack == 2) then
            global_data.playerHealth = global_data.playerHealth - 50
        else
            global_data.playerHealth = global_data.playerHealth - 100
    end
    storyboard.gotoScene(“judge”)
end

function opponent_scene:exitScene( event )
    print(“opponent exit scene”)
    
    local group = self.view

    – body
end

opponent_scene:addEventListener(“createScene”,opponent_scene)
opponent_scene:addEventListener(“enterScene”,opponent_scene)
opponent_scene:addEventListener(“exitScene”,opponent_scene)

return opponent_scene

-----------------------judge scene

local storyboard = require(“storyboard”)
local judge = storyboard.newScene()
local global_data = require(“global_data”)
local twisted = require(“TF”)
local warwick = require(“Warwick”)

function judge:createScene(event)
    local group = self.view

    print("round = "…global_data.round)
    print("player hp = "…global_data.playerHealth)
    print("opponent hp = "…global_data.opponentHealth)
    storyboard.removeScene(“oppponent_scene”)
    global_data.round = global_data.round + 1

    if(global_data.opponentHealth > 0) then
        storyboard.gotoScene(“singlePlayer2”)
    else
        local grats =
        {
            text = “YOU WIN!!!”,
            x = 150,
            y = 250,
            font = native.systemFontBold,
            fontSize = 50
        }
        local text = display.newText(grats)
        group:insert(grats)
        
    end

end

judge:addEventListener(“createScene”,judge)

return judge


i am constantly changing single player… trying to make it work…

so far… i thought puting the player and the opponent outside the create scene (so as to be loaded once)

then in the enter scene i have my event listeners because i want them to be executed every time the scene appears…

as long as i don’t use storyboard.purgeAll() or storyboard.removeScene(“singlePlayer2”) it should not load the view again so it won’t go outside the create scene event right?