Author Topic: CheckPoints and Lives System  (Read 1275 times)

0 Members and 1 Guest are viewing this topic.

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
CheckPoints and Lives System
« on: May 28, 2012, 04:47:53 PM »
I want a total of 10 lives and various checkpoints throughout the game and I think i'm very close with the code i've got, but lack a bit of knowledge.

So this is the code i've got at the moment.

Code: [Select]
function LevelLogic()

        StartLevelLogic()

i = 10

        Puzzle = 0

                CheckConditions()
                coroutine.yield()       
        end
end

function CheckConditions()


        if GetEmpire(1).NumSeedlings == 0 and CheckPoint == 1 and Lives == (i) then
           
i = 9
                        GetAsteroid(10):AddSeedlings(1)
Message("You have 9 Seedlings left.", true, 1.0, "Centre")

        end



end

So i've branched out and i've tried to do some stuff. I knew that I couldn't just do CheckPoint == 1 and Lives == 10 because what if they had 9 lives before they got to the first checkpoint? So I have to make Lives == to 0 - 10 all at the same time, but just thinking now, do I actually need to add Lives == 0 - 10 in that code? I could just add something like this below in seperate if statement such as:

Code: [Select]
if Lives == 10 and GetEmpire(1).NumSeedlings == 0 then
Lives = 9
Message("You have 9 Seedlings left.", true, 1.0, "Centre")
end

Wouldn't that work? Brainwave.

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 899
  • Eufloria: Yes
Re: CheckPoints and Lives System
« Reply #1 on: May 28, 2012, 05:11:50 PM »
Why not use

Code: [Select]
if GetEmpire(1).NumSeedlings == 0 then
  Lives = Lives - 1
  Message("You have " .. Lives .. " seedlings left.", true, 1.0, "Centre")
end

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CheckPoints and Lives System
« Reply #2 on: May 28, 2012, 05:35:58 PM »
Actually that won't work, according to Tom you can't concatenate stuff into a Message string like you can with MessageBoxes.  You also can't use Message to display the value of a variable.

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: CheckPoints and Lives System
« Reply #3 on: May 28, 2012, 05:50:00 PM »
Code: [Select]
if GetEmpire(1).NumSeedlings == 0 and Lives == 10 then
Lives = 9
Message("You have 9 seedlings left.", true, 1.0, "Centre")
end

That would work, surley.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CheckPoints and Lives System
« Reply #4 on: May 28, 2012, 05:54:17 PM »
Yes, with the following caveats:


1) You'd need to make sure you set Lives = 10 somewhere before the While loop begins, otherwise the game will crash because when it checks "if Lives == 10" it will discover that Lives = nil.
2) You'll need 10 seperate conditionals if you want 10 lives!  Are you sure 3 lives isn't enough? :>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: CheckPoints and Lives System
« Reply #5 on: May 28, 2012, 06:13:10 PM »
It's going to be a long level, plus think about difficulty, some people can't move fast and that, but maybe i'll post another level test for this, it should be easy to convert to PC this time.

Code: [Select]
if CheckPoint == 1 then
if GetEmpire(1).NumSeedlings == 0 and Lives == 10 then
GetAsteroid(10):AddSeedlings(1)
Lives = 9
Message("You have 9 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 9 then
GetAsteroid(10):AddSeedlings(1)
Lives = 8
Message("You have 8 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 8 then
GetAsteroid(10):AddSeedlings(1)
Lives = 7
Message("You have 7 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 7 then
GetAsteroid(10):AddSeedlings(1)
Lives = 6
Message("You have 6 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 6 then
GetAsteroid(10):AddSeedlings(1)
Lives = 5
Message("You have 5 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 5 then
GetAsteroid(10):AddSeedlings(1)
Lives = 4
Message("You have 4 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 4 then
GetAsteroid(10):AddSeedlings(1)
Lives = 3
Message("You have 3 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 3 then
GetAsteroid(10):AddSeedlings(1)
Lives = 2
Message("You have 2 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 2 then
GetAsteroid(10):AddSeedlings(1)
Lives = 1
Message("You have 1 seedlings left.", true, 1.0, "Centre")
end
end

Plus you're forgetting, thats 10 for every checkpoint haha.

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: CheckPoints and Lives System
« Reply #6 on: May 28, 2012, 06:14:30 PM »
Would it be easier to put it in a function?

Code: [Select]
if CheckPoint == 1 then
Lives()
end

function Lives()
if GetEmpire(1).NumSeedlings == 0 and Lives == 10 then
GetAsteroid(10):AddSeedlings(1)
Lives = 9
Message("You have 9 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 9 then
GetAsteroid(10):AddSeedlings(1)
Lives = 8
Message("You have 8 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 8 then
GetAsteroid(10):AddSeedlings(1)
Lives = 7
Message("You have 7 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 7 then
GetAsteroid(10):AddSeedlings(1)
Lives = 6
Message("You have 6 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 6 then
GetAsteroid(10):AddSeedlings(1)
Lives = 5
Message("You have 5 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 5 then
GetAsteroid(10):AddSeedlings(1)
Lives = 4
Message("You have 4 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 4 then
GetAsteroid(10):AddSeedlings(1)
Lives = 3
Message("You have 3 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 3 then
GetAsteroid(10):AddSeedlings(1)
Lives = 2
Message("You have 2 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 2 then
GetAsteroid(10):AddSeedlings(1)
Lives = 1
Message("You have 1 seedlings left.", true, 1.0, "Centre")
end
end

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CheckPoints and Lives System
« Reply #7 on: May 28, 2012, 07:01:20 PM »
Agree.  :>

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: CheckPoints and Lives System
« Reply #8 on: May 28, 2012, 08:48:31 PM »
Just realised something else i'll have to do with this,

Code: [Select]
function LivesCheck()
if GetEmpire(1).NumSeedlings == 0 and Lives == 10 then
GetAsteroid(10):AddSeedlings(1)
Lives = 9
Message("You have 9 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 9 then
GetAsteroid(10):AddSeedlings(1)
Lives = 8
Message("You have 8 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 8 then
GetAsteroid(10):AddSeedlings(1)
Lives = 7
Message("You have 7 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 7 then
GetAsteroid(10):AddSeedlings(1)
Lives = 6
Message("You have 6 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 6 then
GetAsteroid(10):AddSeedlings(1)
Lives = 5
Message("You have 5 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 5 then
GetAsteroid(10):AddSeedlings(1)
Lives = 4
Message("You have 4 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 4 then
GetAsteroid(10):AddSeedlings(1)
Lives = 3
Message("You have 3 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 3 then
GetAsteroid(10):AddSeedlings(1)
Lives = 2
Message("You have 2 seedlings left.", true, 1.0, "Centre")
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 2 then
GetAsteroid(10):AddSeedlings(1)
Lives = 1
Message("You have 1 seedlings left.", true, 1.0, "Centre")
end
end

So I have in CheckConditions()

Code: [Select]
if CheckPoint == 1 then
LivesCheck()
end

if i do this

Code: [Select]
if CheckPoint == 2 then
LivesCheck()
end

then really, it's not a new checkpoint, cause it will just go back to Asteroid(10) which for checkpoint 2, I don't want, so to save creating another function i decided to do this

Code: [Select]
function CheckConditions()
if (CheckPoint == 1 or CheckPoint == 2) then
LivesCheck()
end

end

function LivesCheck()
if GetEmpire(1).NumSeedlings == 0 and Lives == 10 then
if CheckPoint == 1 then
GetAsteroid(10):AddSeedlings(1)
end
if CheckPoint == 2 then
GetAsteroid(differentasteroid):AddSeedlings(1)
end
Lives = 9
Message("You have 9 seedlings left.", true, 1.0, "Centre")
end

That would work wouldn't it?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CheckPoints and Lives System
« Reply #9 on: May 28, 2012, 09:39:44 PM »
Interesting problem.  I'd suggest using an array.

Consider this code:

Code: [Select]
function LivesCheck()
if GetEmpire(1).NumSeedlings == 0 and Lives == 10 then
startroid[CheckPoint]:AddSeedlings(1)
Lives = 9
Message("You have 9 seedlings left.", true, 1.0, "Centre")
end


startroid[CheckPoint] is the new part.

startroid is an array; a numbered list.

So suppose CheckPoint = 1

That's like saying:

Code: [Select]
startroid[1]
If CheckPoint = 2, then startroid[CheckPoint] resolves to:

Code: [Select]
startroid[2]

startroid is an array.  Arrays are like numbered lists.  CheckPoint indicates the item number in the list called startroid.

You can read about arrays in the Intermediate guide.  I urge you to read about them if you haven't already.


You'll need to initialise the array like this:


Code: [Select]
startroid = {}
Then you can declare values for each slot like this:

Code: [Select]
startroid[1] = GetAsteroid(10)
startroid[2] = GetAsteroid(12)
startroid[3] = GetAsteroid(16)


Then, you would just need to make sure you increment the CheckPoint variable each time the player reaches a new Check Point.  :>
« Last Edit: May 28, 2012, 09:43:59 PM by annikk.exe »

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: CheckPoints and Lives System
« Reply #10 on: May 29, 2012, 10:07:00 PM »
Okay so this is what i've got Annikk.
Code: [Select]
function LevelLogic()
        StartLevelLogic()

Lives = 10
        Puzzle = 0
startroid = {}
startroid[1] = GetAsteroid(10)
        GetAsteroid(16).Owner = 1
        GetAsteroid(16):Hide(1)

        while GameRunning() do
                if Puzzle == 1 then
                                WaitReal(10)
                                GetAsteroid(12):SendSeedlingsToTarget(0,100,GetAsteroid(13))
                                GetAsteroid(13):SendSeedlingsToTarget(0,100,GetAsteroid(14))
                                GetAsteroid(14):SendSeedlingsToTarget(0,100,GetAsteroid(15))
                                GetAsteroid(15):SendSeedlingsToTarget(0,100,GetAsteroid(16))
                                GetAsteroid(16):SendSeedlingsToTarget(0,100,GetAsteroid(17))
                                GetAsteroid(17):SendSeedlingsToTarget(0,100,GetAsteroid(18))
                                GetAsteroid(18):SendSeedlingsToTarget(0,100,GetAsteroid(19))
                                GetAsteroid(19):SendSeedlingsToTarget(0,100,GetAsteroid(12))
                end

                CheckConditions()
                coroutine.yield()      
        end
end



function CheckConditions()

        if gameFinished then
                return
        end

        if GetEmpire(0).NumDysonTrees == 0 and GetEmpire(0).NumSeedlings == 0 then
                        GameOver(true, "")
                        Message("You successfully protected the Captured Seedlings.~Well Done", true, 1.0, "Centre")
                        WaitMessage(false)
                        WaitDialog()
                        Quit(true)
        end

if (CheckPoint == 1 or CheckPoint == 2) then
LivesCheck()
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 1 then
Lives = 0
GameOver(false, "")
Message("Unfortunately you have failed to complete the tasks.", true, 1.0, "Centre")
WaitMessage(false)
WaitDialog()
Quit(false)
end

end

function LivesCheck()
if GetEmpire(1).NumSeedlings == 0 and Lives == 10 then
startroid[CheckPoint]:AddSeedlings(1)
Lives = 9
Message("You have 9 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
end
end

But you see, what happens is this: (Liking my videos now :D)



(WHY WE NEED YOUTUBE TAGS!!!)

Text Version:

Basically it spawns 10 seedlings straight up, not death then one, death then one, just straight up 10.

« Last Edit: May 29, 2012, 11:58:27 PM by Tomfloria »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CheckPoints and Lives System
« Reply #11 on: May 30, 2012, 09:28:31 AM »
You haven't included the bit where you initialise CheckPoint.

Please can you post the whole thing?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CheckPoints and Lives System
« Reply #12 on: May 30, 2012, 09:37:07 AM »
Code: [Select]
function LivesCheck()
if GetEmpire(1).NumSeedlings == 0 and Lives == 10 then
startroid[CheckPoint]:AddSeedlings(1)
Lives = 9
Message("You have 9 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
end
end

Try removing the WaitReal(4) command from this bit?

I suspect WaitReal() doesn't work well when used inside a loop...

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: CheckPoints and Lives System
« Reply #13 on: May 30, 2012, 11:14:23 AM »
Okay, if you want the whole thing... I'll split into functions just incase you don't want something...

function LevelSetup()
Code: [Select]
function LevelSetup()

        SetBackdropColour(200,200,200)

       

--Custom Story Mode Created by: Tomfloria
--Wouldn't have been possible without help from: Annikk.exe, Aino, Pilchard123
--iOS installation tutorial can be found here: http://www.dyson-game.com/smf/index.php?topic=1541.0
--Big thanks to the creaters of Eufloria, without them I wouldn't have done this.
--Contact me at Thomasbiggin@gmail.com

       

       

    Globals():Get("Asteroids"):Set("RadiusPowerRule",4)
        Globals():Get("Asteroids"):Set("SizeFromEnergy",530)
        Globals():Get("Asteroids"):Set("SizeFromStrength",530)
        Globals():Get("Asteroids"):Set("SizeFromSpeed",540)
        Globals():Get("Asteroids"):Set("MinCoreHealth",75)
        Globals():Get("Asteroids"):Set("MaxCoreHealth",350)
        Globals():Get("Asteroids"):Set("CoreHealthPowerRule",2.5)
    Globals():Get("Asteroids"):Set("MinSendDistance",3500)
    Globals():Get("Asteroids"):Set("MaxSendDistance",5500)
    Globals():Get("Asteroids"):Set("SendPowerRule",2.0)
        Globals():Get("Asteroids"):Set("SpawnCap", 20)
        Globals():Get("Structures"):Set("LevelDuration1",15)
        Globals():Get("Structures"):Set("LevelDuration2",30)
        Globals():Get("Structures"):Set("LevelDuration3",60)
        Globals():Get("Structures"):Set("LevelDuration4",100)
        Globals():Get("Structures"):Set("SpawnTime1",15)
        Globals():Get("Structures"):Set("SpawnTime2",12)
        Globals():Get("Structures"):Set("SpawnTime3",10)
        Globals():Get("Structures"):Set("SpawnTime4",8)
        Globals():Get("Flowers"):Set("Available",0)
        Globals():Get("Game"):Set("GreysProbability",0)

        --FIRST PATH TO PUZZLE--

        a = AddAsteroidWithAttribs(0,0, 0.0,0.0,0.5)
        a.Owner = 1
        --a:AddSeedlings(1)
        a:SetRadius(180)
        a.TreeCap = 0
        a:Reveal(1)
       
        a = AddAsteroidWithAttribs(100,-600, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)
        a.Owner = 1
        a:SetRadius(math.random(150,400))
        a.TreeCap = 0
        a.Moveable = false
        a.SendDistance = 100
        a:Reveal(1)

        a = AddAsteroidWithAttribs(-1000,-2300, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)
        a.Owner = 1
        a:SetRadius(math.random(150,400))
        a.TreeCap = 0
        a.Moveable = false
        a.SendDistance = 100
        a:Reveal(1)

       

        a = AddAsteroidWithAttribs(200,-4000, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)

        a.Owner = 1

        a:SetRadius(math.random(150,400))

        a.TreeCap = 0

        a.Moveable = false

        a.SendDistance = 100

        a:Reveal(1)

       

        a = AddAsteroidWithAttribs(3000,-3500, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)

        a.Owner = 1

        a:SetRadius(math.random(150,400))

        a.TreeCap = 0

        a.Moveable = false

        a.SendDistance = 100

        a:Reveal(1)

       

        a = AddAsteroidWithAttribs(3000,-1300, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)

        a.Owner = 1

        a:SetRadius(math.random(150,400))

        a.TreeCap = 0

        a.Moveable = false

        a.SendDistance = 100

        a:Reveal(1)

       

        a = AddAsteroidWithAttribs(4000,1000, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)

        a.Owner = 1

        a:SetRadius(math.random(150,400))

        a.TreeCap = 0

        a.Moveable = false

        a.SendDistance = 100

        a:Reveal(1)

       

        a = AddAsteroidWithAttribs(6000,-1000, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)

        a.Owner = 1

        a:SetRadius(math.random(150,400))

        a.TreeCap = 0

        a.Moveable = false

        a.SendDistance = 100

        a:Reveal(1)

       

       

        a = AddAsteroidWithAttribs(8000,-3500, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)

        a.Owner = 1

        a:SetRadius(math.random(150,400))

        a.TreeCap = 0

        a.Moveable = false

        a.SendDistance = 100

        a:Reveal(1)

       

       

        a = AddAsteroidWithAttribs(8500,-5500, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)

        a.Owner = 1

        a:SetRadius(math.random(150,400))

        a.TreeCap = 0

        a.Moveable = false

        a.SendDistance = 100

        a:AddSeedlings(1)

        a:Reveal(1)

       

        a = AddAsteroidWithAttribs(8500,-7500, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)

        a.Owner = 1

        a:SetRadius(math.random(150,400))

        a.TreeCap = 0

        a.Moveable = false

        a.SendDistance = 100

        a:Hide(1)

       

       

        --END OF PATH TO PUZZLE--

       

        --START OF PUZZLE--THE PRATROLERS

       

        --MIDDLE ASTEROID--11

        a = AddAsteroidWithAttribs(8500,-13000, math.random(2,5) / 10,math.random(2,5) / 10,math.random(2,5) / 10)

        a.Owner = 1

        a:SetRadius(300)

        a.Moveable = false

        a:Hide(1)



       

        --BOTTOM ASTEROID--12

        a = AddAsteroidWithAttribs(8500,-10000, 1,1,0.3)

        a.Owner = 1

        a.TreeCap = 0

        a.Moveable = false

        a:SetRadius(200)

        a:Hide(1)

       

        --BOTTOM LEFT ASTEROID--13

        a = AddAsteroidWithAttribs(6500,-11000, 1,1,0.3)

        a.Owner = 0

        a.TreeCap = 0

        a:AddSeedlings(100)

        a.Moveable = false

        a:SetGraceTime(999999)

        a:SetRadius(200)

        a:Hide(1)

       

        --LEFT ASTEROID--14

        a = AddAsteroidWithAttribs(5500,-13000, 1,1,0.3)

        a.Owner = 0

        a.TreeCap = 0

        a:AddSeedlings(100)

        a.Moveable = false

        a:SetGraceTime(999999)

        a:SetRadius(200)

        a:Hide(1)

       

        --TOP LEFT ASTEROID--15

        a = AddAsteroidWithAttribs(6500,-15000, 1,1,0.3)

        a.Owner = 0

        a.TreeCap = 0

        a:AddSeedlings(100)

        a.Moveable = false

        a:SetGraceTime(999999)

        a:SetRadius(200)

        a:Hide(1)

       

        --TOP ASTEROID--16

        a = AddAsteroidWithAttribs(8500,-16000, 1,1,0.3)

        a.Owner = 0

        a.TreeCap = 0

        a:AddSeedlings(100)

        a.Moveable = false

        a:SetGraceTime(999999)

        a:SetRadius(200)

        a:Hide(1)

       

        --TOP RIGHT ASTEROID--17

        a = AddAsteroidWithAttribs(10500,-15000, 1,1,0.3)

        a.Owner = 0

        a.TreeCap = 0

        a:AddSeedlings(100)

        a.Moveable = false

        a:SetGraceTime(999999)

        a:SetRadius(200)

        a:Hide(1)

       

        --RIGHT ASTEROID--18

        a = AddAsteroidWithAttribs(11500,-13000, 1,1,0.3)

        a.Owner = 0

        a.TreeCap = 0

        a:AddSeedlings(100)

        a.Moveable = false

        a:SetGraceTime(999999)

        a:SetRadius(200)

        a:Hide(1)

       

        --BOTTOM RIGHT ASTEROID--19

        a = AddAsteroidWithAttribs(10500,-11000, 1,1,0.3)

        a.Owner = 0

        a.TreeCap = 0

        a:AddSeedlings(100)

        a.Moveable = false

        a:SetGraceTime(999999)

        a:SetRadius(200)

        a:Hide(1)

       

        --END OF PUZZLE 1--

       

        --SECOND PATH TO PUZZLE 2--

       

        a = AddAsteroidWithAttribs(10500,-19000, 1,1,0.3)

        a.Owner = 1

        a:SetRadius(math.random(150,400))

        a.TreeCap = 0

        a.Moveable = false

        a.SendDistance = 100

        a:Reveal(1)

       

        SetDysonTreeButtonAvailable(false)

        SetDefenseTreeButtonAvailable(false)

        SetFlowerDefenseButtonAvailable(false)

        SetFlowerSeederButtonAvailable(false)

        SetTerraformingButtonAvailable(false)

        SetBeaconButtonAvailable(false)



        if IsiOS() then

                SetEnemyInfoAvailable(true)

                SetCoreInfoAvailable(true)

                SetAttribsInfoAvailable(true)



                SetSpeedSwitchAvailable(true)

                SetSendModeScoutAvailable(true)

                SetSendModeUnitsSelectorAvailable(true)



                SetSendModeButtonAvailable(true)

                SetSendModeHoldAvailable(true)

                SetSendModeDragAvailable(true)

        else

                SetTreeInfoAvailable(true)

                SetEnemyInfoAvailable(true)

                SetCoreInfoAvailable(true)

                SetAttribsInfoAvailable(true)

        end

       

        SetCameraPosition(0,0)

       

end


function LevelLogic()
Code: [Select]
function LevelLogic()
        StartLevelLogic()

Lives = 10
        Puzzle = 0
startroid = {}
startroid[1] = GetAsteroid(9)
startroid[2] = GetAsteroid(9)
        GetAsteroid(16).Owner = 1
        GetAsteroid(16):Hide(1)

        while GameRunning() do
                if Puzzle == 1 then
                                WaitReal(10)
                                GetAsteroid(12):SendSeedlingsToTarget(0,100,GetAsteroid(13))
                                GetAsteroid(13):SendSeedlingsToTarget(0,100,GetAsteroid(14))
                                GetAsteroid(14):SendSeedlingsToTarget(0,100,GetAsteroid(15))
                                GetAsteroid(15):SendSeedlingsToTarget(0,100,GetAsteroid(16))
                                GetAsteroid(16):SendSeedlingsToTarget(0,100,GetAsteroid(17))
                                GetAsteroid(17):SendSeedlingsToTarget(0,100,GetAsteroid(18))
                                GetAsteroid(18):SendSeedlingsToTarget(0,100,GetAsteroid(19))
                                GetAsteroid(19):SendSeedlingsToTarget(0,100,GetAsteroid(12))
                end

                CheckConditions()
                coroutine.yield()       
        end
end


function CheckConditions()
Code: [Select]
function CheckConditions()

        if gameFinished then
                return
        end

        if GetEmpire(0).NumDysonTrees == 0 and GetEmpire(0).NumSeedlings == 0 then
                        GameOver(true, "")
                        Message("You successfully protected the Captured Seedlings.~Well Done", true, 1.0, "Centre")
                        WaitMessage(false)
                        WaitDialog()
                        Quit(true)
        end

LivesCheck()

if GetEmpire(1).NumSeedlings == 0 and Lives == 1 then
Lives = 0
GameOver(false, "")
Message("Unfortunately you have failed to complete the tasks.", true, 1.0, "Centre")
WaitMessage(false)
WaitDialog()
Quit(false)
end

end

function LivesCheck()
Code: [Select]
function LivesCheck()
if GetEmpire(1).NumSeedlings == 0 and Lives == 10 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 9 seedlings left.", true, 1.0, "Centre")
Lives = 9
end

if Lives == 9 then
if GetEmpire(1).NumSeedlings == 0 then
startroid[CheckPoint]:AddSeedlings(1)
end
Message("You have 8 seedlings left.", true, 1.0, "Centre")
Lives = 8
end
if GetEmpire(1).NumSeedlings == 0 and Lives == 8 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 7 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
Lives = 7
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 7 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 6 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
Lives = 6
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 6 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 5 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
Lives = 5
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 5 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 4 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
Lives = 4
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 4 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 3 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
Lives = 3
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 3 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 2 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
Lives = 2
end

if GetEmpire(1).NumSeedlings == 0 and Lives == 2 then
startroid[CheckPoint]:AddSeedlings(1)
Message("You have 1 seedlings left.", true, 1.0, "Centre")
WaitReal(4)
Lives = 1
end
end

function OnAsteroidRevealed(id, owner)
Code: [Select]
function OnAsteroidRevealed(id, owner)

        if id == 10 then
                Puzzle = 1
                GetAsteroid(11):Reveal(1)
                GetAsteroid(12):Reveal(1)
                GetAsteroid(13):Reveal(1)
                GetAsteroid(14):Reveal(1)
                GetAsteroid(15):Reveal(1)
                GetAsteroid(16):Reveal(1)
                GetAsteroid(17):Reveal(1)
                GetAsteroid(18):Reveal(1)
                GetAsteroid(19):Reveal(1)
                CheckPoint = 1
        end
end

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: CheckPoints and Lives System
« Reply #14 on: May 30, 2012, 03:52:57 PM »
Looking at it now.

By the way, a tip I would give you is to use tabs instead of spaces for the code spacing.

For example:


Code: [Select]
function LevelLogic()
if 1 == 1 then
GetAsteroid(0):AddSeedlings(10)
end
end

Instead of:

Code: [Select]
function LevelLogic()
     if 1 == 1 then
          GetAsteroid(0):AddSeedlings(10)
    end
end


That way things line with each other up automatically. :>


Here are those two code snippets again, screenshotted in Notepad++ for comparison:






The lines showing which if pertains to which end, get messed up if you use spaces.
Also it means it takes longer (using cursor keys) to get to the end or start of a deeply nested line, because you have to scroll through 30 spaces first (instead of 6 tabs).



Minor point, and this isn't the cause of your Lives/Checkpoint problem, but I thought I'd mention it here...