Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

TIC-80

Fantasy computer for making, playing and sharing tiny games. · By Nesbox

Coding help for a simple wait/loop

A topic by Ghegs created Apr 01, 2019 Views: 709 Replies: 1
Viewing posts 1 to 2

Hi,

I've been struggling to figure this seemingly basic thing out for a few days now, but to no avail. I'm just trying to create a simple Simon Says-type of game to acquaint myself with Lua in general. The problem is that I can't get the generated pattern to be displayed properly to the player, so that each item in the pattern is shown for a few seconds on-screen before moving to the next. It does loop through the pattern, but in a flash. Here's what I have:

function Init()
    sR=15 -- small radius
    lR=22 -- large radius
    Yellow={
        x=120,
        y=30,
        r=sR,
        c=14
    }
    Green={
        x=120,
        y=100,
        r=sR,
        c=11    
    }
    Blue={
        x=80,
        y=65,
        r=sR,
        c=8
    }
    Red={
        x=160,
        y=65,
        r=sR,
        c=6
    }
    pattern={}
    for i=1,5,1 do
        table.insert(pattern,(math.random(0,3)))
    end
end
function Draw()
    circ(Yellow.x, Yellow.y, Yellow.r, Yellow.c)
    circ(Green.x, Green.y, Green.r, Green.c)
    circ(Blue.x, Blue.y, Blue.r, Blue.c)
    circ(Red.x, Red.y, Red.r, Red.c)
end
Init()
playerturn=false
t=0
function TIC()
    t=t+1
    
    if playerturn==false then
        for i=1, #pattern do
            Yellow.r=sR
            Green.r=sR
            Blue.r=sR
            Red.r=sR
            if pattern[i]==0 then Yellow.r=lR end
            if pattern[i]==1 then Green.r=lR end
            if pattern[i]==2 then Blue.r=lR end
            if pattern[i]==3 then Red.r=lR end
            cls()
            if t<2*60 then
                Draw()
            else t=0 end
        end
     playerturn=true           
     return
    end
    
    if playerturn==true then
        --truncated for clarity, the player's button presses will be compared against the pattern, etc
    end
end

For the example's sake I truncated parts of the code not relevant to the question, and the pattern length is hard-coded at five. Any help would be appreciated.

I think you should ask on FC discord, there's a large TIC-80 community:

https://discordapp.com/invite/sFeDxWK