magicskillz's questions

When you post code, put 3~'s on a line before and after you code. Check the upper and lower case letters on gamestate. You also have multiple setup() and draw() functions. You should only have one of each.

@dave1707
were do I have to fix the gamestate’s?

Still it isn’t working it shows a black screen

@magicskillz Try this.

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

function setup()
    gameState=0
    x=100
    y=300
    cam = vec2(0,0)
    done=true
    cb={x=60,y=300}
    val=2
end

function draw()
    if gameState==0 then
        font("Copperplate-Bold")
        fontSize(75)
        --title
        fill(0, 255, 8, 255)
        text("Mad Dash",WIDTH/2, HEIGHT/1.19)
        fontSize(25)
        text("Tap screen to start.",WIDTH/2, HEIGHT/2)
        --Name
        fill(235, 5, 10, 255)
        textAlign(CORNER)
        text("By Magic Skillz", WIDTH/6, HEIGHT/30)
    end
    if gameState==2 then
        cam.x = cam.x - DeltaTime*119.3
        background(40, 40, 50)
        fill(255)
        translate(cam.x,cam.y)
        x=x+3
        cb.x=cb.x+val -- move sprite 
        sprite("Planet Cute:Character Boy",cb.x,cb.y)    
    end
end
        
function jumpTween()
    t1=tween(.5,cb,{y=400},tween.easing.cubicOut)
    t2=tween(.5,cb,{y=300},tween.easing.cubicIn,tweenDone)
    tween.sequence(t1,t2)   
end

function duckTween()
    t1=tween(.5,cb,{y=200},tween.easing.cubicOut)
    t2=tween(.5,cb,{y=300},tween.easing.cubicIn,tweenDone)
    tween.sequence(t1,t2)   
end

function tweenDone()
    done=true   -- tween is done, allow next jump 
end

function touched(t)
    if t.state==BEGAN and gameState==0 then
        gameState=2
        return
    end
    if t.state==MOVING and done then
        done=false
        if t.deltaY<0 then 
            duckTween()
        else
            jumpTween()
        end
    end
end

Wow, thank you

What is wrong with this code it says as an error:
Main:45: ‘for’ limit must be a
number
stack traceback:
Main:45: In function draw

I can’t figure out were the problem is. Here is my code:
`

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

function setup()
    gameState=0
    x=100
    y=300
    cam = vec2(0,0)
    done=true
    cb={x=60,y=300}
    val=2   
end
function draw()
    if gameState==0 then
        font("Copperplate-Bold")
        fontSize(75)
        --title
        fill(0, 255, 8, 255)
        text("Mad Dash",WIDTH/2, HEIGHT/1.19)
        fontSize(25)
        text("Tap screen to start.",WIDTH/2, HEIGHT/2)
        --Name
        fill(235, 5, 10, 255)
        textAlign(CORNER)
        text("By Magic Skillz", WIDTH/6, HEIGHT/30)
    end
    if gameState==2 then
        xpos=0
        cam.x = cam.x - DeltaTime*119.3
        background(40, 40, 50)
        fill(255)
        translate(cam.x,cam.y)
        x=x+3
        cb.x=cb.x+val -- move sprite 
        sprite("Planet Cute:Character Boy",cb.x,cb.y)
        spike={1,0,0,0,0,0,0,0,0}
        box={0,0,1,2,3,4,3,2,1,0}
         for i = 1,12 do
--the value in the current position (i) of the ground array is the number of blocks high to 
--draw at the current position
        for h=1,spike[i] do
            --draw the sprite at the current x position i * width of one sprite with the xpos
            --offset which creates the movement
            --the y position is calculated as a multiplier of the the height
            sprite("Planet Cute:Ramp South",xpos+100*i-100,-40+70*h,100,100)
        end       
        --repeat the process for the ceiling
        for h=1,box[i] do
            sprite("Planet Cute:Ramp South",xpos+100*i-100,-40+70*h,100,100)
        end           
    end
        temp=spike[1]--ground=spike
        tempr=box[1]--roof=box
        for c=1,#spike-1 do
            spike[c]=spike[c+1]
            box[c]=box[c+1]
        end
--{b,c,d,d} becomes {b,c,d,a}
        spike[#spike]=temp
        box[#box]=tempr   
    end
end
function jumpTween()
    t1=tween(.5,cb,{y=400},tween.easing.cubicOut)
    t2=tween(.5,cb,{y=300},tween.easing.cubicIn,tweenDone)
    tween.sequence(t1,t2)   
end

function duckTween()
   t1=tween(.5,cb,{y=200},tween.easing.cubicOut)
  t2=tween(.5,cb,{y=300},tween.easing.cubicIn,tweenDone)
   tween.sequence(t1)   
end

function tweenDone()
    done=true   -- tween is done, allow next jump 
end

function touched(t)
    if t.state==BEGAN and gameState==0 then
        gameState=2
        return
    end
    if t.state==MOVING and done then
        done=false
        if t.deltaY<0 then 
            duckTween()
        else
            jumpTween()
        end
    end
end

`

The problem is in or near line 45. One of the numbers in the for statement isn’t a number. Also, just put 3~'s on a line by themselves. You also have a '. Edit your code above and correct the lines with the 3~'s.

The table spike has 9 values in it. The loop for i=1,12 causes i to go from 1 to 12. So the next loop for h=1,spike[i] causes spike[i] to go beyond the table size resulting in a nil value.

@dave1707
Ok I’ll try that

@dave1707
It worked thanks a lot that saved a lot of my problems :slight_smile:

@magicskillz - you need to be able to debug very simple errors like this yourself, if you want to tackle more complex projects in the future.

What I would do to find this error is, once I know the error is in the numbers for the for loop, is put in a print statement just before it, so I’d have this

    for i = 1,12 do
        print (i, spike[i]) --<<<
        for h=1,spike[i] do

This would quickly pick up the problem.

That’s exactly what I did to find the error. When i became 10, spike[i] printed nil. I looked at the spike table and saw that it was only 9 entries long.

@Ignatz
Thanks for the trick for debuging