Assistance with calling a draw class

Hello.
For an assignment piece I am coding an app that controls many of the annoying bits of a board game I have made - not important but background info.

Basically, I had a menu set up but I didn’t like it and I am now redesigning it.
Here is the main code chunk:

-- BoardGame

-- Use this function to perform your initial setup
aa = math.random(8)
bb = math.random(8)
cc = math.random(8)
dd = math.random(8)
sw = 1024
crysis = 255
hamish = 60
sh = 768
sniper = 0
watch = 0
--beginning
a = 1
--menu
b = 2
--good
c = 3
--one disk, reshuffle, roll of a dice
d = 4
--what is it, how to play, victory, aligning rings
e = 5
--good
f = 6
--right
g = 7
--wrong
h = 9
--evil
i = 10
--one disk
j = 11
--what is it
k = 12
--roll of a dice
l = 13
m = 14
n = 15
o = 16
p = 17
q = 18
dir1 = "x"
dir2 = "x"
dir3 = "x"
dir4 = "x"
mainfont = 100
secfont = 70
thirfont = 5
country = 0
land = 0
object = 0
poss = 0
cmessage = 1
bmessage = 0
ore = "x"
dice = "x"
memprev = b
GAME_STATE = a
gconseq = 0
gending = 0
gresult = 0
econseq = 0
eending = 0
eresult = 0
rconseq = 0
rending = 0
rresult = 0
wconseq = 0
wending = 0
wresult = 0
touch = t
--'Roll again'
--'Switch positions with anyone on the board if you desire so'
--'Turn a disk as many spaces as you like'

--'Move back to where you were at the beginning of this turn'
--'Miss a turn'
--'The player to your left can turn a disk as many spaces as they like'
function setup()
    displayMode(FULLSCREEN)
    supportedOrientations(LANDSCAPE_ANY)
    end

function draw()
    gresult = math.random(3)
    if gresult == 3 then
    gconseq = 'Switch positions with anyone on the board if you desire so'
    elseif gresult == 2 then
    gconseq = 'Roll again'
    elseif gresult == 1 then
    gconseq = 'Turn a disk as many spaces as you like'
    end
    eresult = math.random(3)
    if eresult == 3 then
    econseq = 'Move back to where you were at the beginning of this turn'
    elseif eresult == 2 then
    econseq = 'Miss a turn'
    elseif eresult == 1 then
    econseq = 'The player to your left can turn a disk as many spaces as they like'
    end
    wresult = math.random(4)
    if wresult == 1 or wresult == 2 then
    wconseq = 'Move back to where you were at the beginning of this turn'
    elseif wresult == 3 or wresult == 4 then
    wconseq = 'Miss a turn'
    end
    rresult = math.random(4)
    if rresult == 1 or rresult == 2 then
    rconseq = 'Turn a disk as many spaces as you like'
    elseif rresult == 3 or rresult == 4 then
    rconseq = 'Roll again'
    end
    
    bmessage = math.random(3)
    mainfont = 100
    secfont = 70
    thirfont = 400
    country = math.random(16)
    if country == 1 then
    country = 'Australia'
    elseif country == 2 then
    country = 'the United States'
    elseif country == 3 then
    country = 'Pakistan'
    elseif country == 4 then
    country = 'India'
    elseif country == 5 then
    country = 'Russia'
    elseif country == 6 then
    country = 'Japan'
    elseif country == 7 then
    country = 'Thailand'
    elseif country == 8 then
    country = 'Syria'
    elseif country == 9 then
    country = 'South Africa'
    elseif country == 10 then
    country = 'Germany'
    elseif country == 11 then
    country = 'France'
    elseif country == 12 then
    country = 'Scotland'
    elseif country == 13 then
    country = 'England'
    elseif country == 14 then
    country = 'New Zealand'
    elseif country == 15 then
    country = 'Canada'
    else
    country = 'Argentina'
    end
    
poss = math.random(16)
    if poss == 1 then
    poss = 'carrots'
    elseif poss == 2 then
    poss = 'gold'
    elseif poss == 3 then
    poss = 'iron'
    elseif poss == 4 then
    poss = 'grain'
    elseif poss == 5 then
    poss = 'pearls'
    elseif poss == 6 then
    poss = 'marble'
    elseif poss == 7 then
    poss = 'money'
    elseif poss == 8 then
    poss = 'drumsticks'
    elseif poss == 9 then
    poss = 'weapons'
    elseif poss == 10 then
    poss = 'vehicles'
    elseif poss == 11 then
    poss = 'wheel barrows'
    elseif poss == 12 then
    poss = 'iPads'
    elseif poss == 13 then
    poss = 'pencils'
    elseif poss == 14 then
    poss = 'bananas'
    elseif poss == 15 then
    poss = 'cattle'
    else
    poss = 'cotton'
    end
    
    --oscillating alpha
    crysis = crysis + (sniper)
        if crysis == 255 then
            sniper = -5
            end
        if crysis == 0 then
            sniper = 5
            end
    
    hamish = hamish + (watch)
        if hamish == 60 then
            watch = -5
            end
        if hamish == 0 then
            watch = 5
            end
    
    if GAME_STATE == a then  
    background(91, 45, 81, 255)
    fill(255, 255, 255, 255)
    fontSize(mainfont)
    font("AmericanTypewriter-Bold")
    text('CIRCUMFERENCE', sw/2, sh/2+100)
    fontSize(secfont)
    fill(196, 196, 196, 255)
    rect(sw/2-270, sh/2-150, 540, 100)
    fill(0, 0, 0, 255)
    rect(sw/2-270+5, sh/2-150+5, 530, 90)
    fill(196, 196, 196, crysis)
    text('Touch To Start', sw/2, sh/2-100)
    end
    --MENU SCREEN
    if GAME_STATE == b then
    background(91, 45, 81, 255)
    fontSize(50)
    fill(196, 196, 196, 255)
    rect(sw/2-580, sh/2+250, 540, 100)
    fill(0, 0, 0, 255)
    rect(sw/2-575, sh/2+255, 530, 90)
    fill(255, 255, 255, 255)
    text('Good', sw/2-250, sh/2+300)
        
    fill(196, 196, 196, 255)
    rect(sw/2-580, sh/2+100, 540, 100)
    fill(0, 0, 0, 255)
    rect(sw/2-575, sh/2+105, 530, 90)
    fill(255, 255, 255, 255)
    text('Right', sw/2-250, sh/2+150)
        
    fill(196, 196, 196, 255)
    rect(sw/2-580, sh/2-50, 540, 100)
    fill(0, 0, 0, 255)
    rect(sw/2-575, sh/2-45, 530, 90)
    fill(255, 255, 255, 255)
    text('Wrong', sw/2-250, sh/2)
        
    fill(196, 196, 196, 255)
    rect(sw/2-580, sh/2-200, 540, 100)
    fill(0, 0, 0, 255)
    rect(sw/2-575, sh/2-195, 530, 90)
    fill(255, 255, 255, 255)
    text('Evil', sw/2-250, sh/2-150)
    
    fill(196, 196, 196, 255)
    rect(sw/2-580, sh/2-350, 540, 100)
    fill(0, 0, 0, 255)
    rect(sw/2-575, sh/2-345, 530, 90)
    fill(255, 255, 255, 255)
    text('Dice Roll', sw/2-250, sh/2-300)
        
    fill(196, 196, 196, 255)
    rect(sw/2+40, sh/2+250, 540, 100)
    fill(0, 0, 0, 255)
    rect(sw/2+45, sh/2+255, 530, 90)
    fill(255, 255, 255, 255)
    text('What is it?', sw/2+310, sh/2+300)    
        
    fill(196, 196, 196, 255)
    rect(sw/2+40, sh/2+100, 540, 100)
    fill(0, 0, 0, 255)
    rect(sw/2+45, sh/2+105, 530, 90)
    fill(255, 255, 255, 255)
    text('How to Play', sw/2+310, sh/2+150)
        
    fill(196, 196, 196, 255)
    rect(sw/2+40, sh/2-50, 540, 100)
    fill(0, 0, 0, 255)
    rect(sw/2+45, sh/2-45, 530, 90)
    fill(255, 255, 255, 255)
    text('Aligning Disks', sw/2+310, sh/2)
        
    fill(196, 196, 196, 255)
    rect(sw/2+40, sh/2-200, 540, 100)
    fill(0, 0, 0, 255)
    rect(sw/2+45, sh/2-195, 530, 90)
    fill(255, 255, 255, 255)
    text('Victory', sw/2+310, sh/2-150)
    
    fill(196, 196, 196, 255)
    rect(sw/2+40, sh/2-350, 540, 100)
    fill(0, 0, 0, 255)
    rect(sw/2+45, sh/2-345, 530, 90)
    fill(255, 255, 255, 255)
    text('Shuffle', sw/2+310, sh/2-300)
    
end
end
function touched(t)
--taptoplay
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-145 and CurrentTouch.y < sh/2-145+90 and GAME_STATE == a then
    GAME_STATE = b
    end     
--back button
    if CurrentTouch.x > sw/2+305 and CurrentTouch.x < sw/2+305+90
    and CurrentTouch.y > sh/2-150+5-100 and CurrentTouch.y < sh/2-150+5-100+90 and GAME_STATE ~= b then
    GAME_STATE = b
    end
--good
    if CurrentTouch.x > 0 and CurrentTouch.x < sw/2-40
    and CurrentTouch.y > sh/2+255 and CurrentTouch.y < sh/2+345 then
    GAME_STATE = c
    Good:draw()
    end
end

I put most of it in the main tab, but right at the bottom you will notice there is a class call (will include class in reply) but whenever I call it, instead of blocking out the screen with delightful green, a quick tap brings a fast flickering image, a held tap lowers the rate and after a few seconds of hold it will then be blocked in.

I know there is a bunch of problems with the code like variables that do not make sense and all the rest - it is okay. I have them all in a scrap tab which was the old version I am converting (will include). If anyone can help with this flickering it would be much appreciated!

Class:

Good = class()

function Good:init(x)
    -- you can accept and set parameters here
    self.x = x
end

function Good:draw()
    -- Codea does not automatically call this method
        --GOOD
    if GAME_STATE == c then
    background(59, 121, 60, 255)
    fontSize(25)
    fill(255, 255, 255, 255)
    font("AmericanTypewriter-Bold")
    if cmessage == 1 then
    text("You give a large donation of "..object.." to "..land..".", sw/2, sh/2)
    elseif cmessage == 2 then
    text("You send some troops over to "..land.." to help them in a war.", sw/2, sh/2)
    elseif cmessage == 3 then
    text(land.." is having all of their "..object.." stolen but you take action.", sw/2, sh/2)
    end
    text(gending, sw/2, sh/2-40)
            --Back Button
    fill(196, 196, 196, 255)
    rect(sw/2+300, sh/2-150-100, 100, 100)
    fill(0, 0, 0, 255)
    rect(sw/2+300+5, sh/2-150+5-100, 90, 90)
    sprite("Cargo Bot:Command Left", sw-160, sh/2-200)
end
end

function Good:touched(touch)
    -- Codea does not automatically call this method
end

Scrap:


    if GAME_STATE == i then
    background(183, 31, 55, 255)
    fontSize(25)
    fill(255, 255, 255, 255)
    font("AmericanTypewriter-Bold")
    if cmessage == 1 then
    text("You decide to invade "..land.." and steal all their "..object..".", sw/2, sh/2)
    elseif cmessage == 2 then
    text("You commit a genocide against "..land..".", sw/2, sh/2)
    elseif cmessage == 3 then
    text("You murder many refugees that fled "..land.." and came to you.", sw/2, sh/2)
    end
    text(eending, sw/2, sh/2-40)
                --Back Button
    fill(196, 196, 196, 255)
    rect(sw/2+300, sh/2-150-100, 100, 100)
    fill(0, 0, 0, 255)
    rect(sw/2+300+5, sh/2-150+5-100, 90, 90)
    sprite("Cargo Bot:Command Left", sw-160, sh/2-200)
    end
    
    if GAME_STATE == h then
    background(255, 169, 0, 255)
    fontSize(25)
    fill(255, 255, 255, 255)
    font("AmericanTypewriter-Bold")
    if cmessage == 1 then
    text("You are in "..land.." but you do not follow their laws.", sw/2, sh/2)
    elseif cmessage == 2 then
    text("You steal "..object.." from "..land..".", sw/2, sh/2)
    elseif cmessage == 3 then
    text("You allow discrimination to occur against people from "..land..".", sw/2, sh/2)
    end
    text(wending, sw/2, sh/2-40)
                --Back Button
    fill(196, 196, 196, 255)
    rect(sw/2+300, sh/2-150-100, 100, 100)
    fill(0, 0, 0, 255)
    rect(sw/2+300+5, sh/2-150+5-100, 90, 90)
    sprite("Cargo Bot:Command Left", sw-160, sh/2-200)
    end
    
    if GAME_STATE == g then
    background(65, 83, 222, 255)
    fontSize(25)
    fill(255, 255, 255, 255)
    font("AmericanTypewriter-Bold")
    if cmessage == 1 then
    text("You stop the discrimination against people from "..land..".", sw/2, sh/2)
    elseif cmessage == 2 then
    text("You forget and forgive "..land.." for their previous actions.", sw/2, sh/2)
    elseif cmessage == 3 then
    text("Whilst travelling through "..land.." you follow their laws.", sw/2, sh/2)
    end
    text(rending, sw/2, sh/2-40)
                --Back Button
    fill(196, 196, 196, 255)
    rect(sw/2+300, sh/2-150-100, 100, 100)
    fill(0, 0, 0, 255)
    rect(sw/2+300+5, sh/2-150+5-100, 90, 90)
    sprite("Cargo Bot:Command Left", sw-160, sh/2-200)
    end
    
    
        
    
    if GAME_STATE == k then
    background(91, 45, 81, 255)
    fill(255, 255, 255, 255)
    fontSize(20)
    text('Circumference is a game where 2 — 4 players battle it out and compete against each other to race', sw/2, sh/2+80)
    text('from one side of the board to the other whilst receiving cards which may either hinder or help', sw/2, sh/2+60)
    text('them on their quest to moral victory. On the board the are spaces eight different colours spread', sw/2, sh/2+40)
    text(' across four different rings which rotate around a pentagonal centre piece. Black spaces are', sw/2, sh/2+20)
    text('impassable, yellow spaces have no effect on the player, however the green (Good), red (Evil),', sw/2, sh/2)
    text('orange (Wrong), and blue (Right) spaces will provide cards which may aid or handicap the players.', sw/2, sh/2-20)
    fill(196, 196, 196, 255)
    rect(sw/2+300, sh/2-150-100, 100, 100)
    fill(0, 0, 0, 255)
    rect(sw/2+300+5, sh/2-150+5-100, 90, 90)
    sprite("Cargo Bot:Command Left", sw-160, sh/2-200)
    end
    
    if GAME_STATE == j then
    background(91, 45, 81, 255)
    fontSize(25)
    font("Baskerville-Italic")
    fill(255, 255, 255, 255)
    text(ore..", "..dir1, sw/2, sh/2+100)
    --StopSpin
    fill(196, 196, 196, 255)
    rect(sw/2+60, sh/2-150-100, 100, 100)
    fill(255, 0, 0, 255)
    rect(sw/2+60+5, sh/2-150+5-100, 90, 90)
    --Spin
    fill(196, 196, 196, 255)
    rect(sw/2-60-100, sh/2-150-100, 100, 100)
    fill(1, 255, 0, 255)
    rect(sw/2-60-100+5, sh/2-150+5-100, 90, 90)
                --Back Button
    fill(196, 196, 196, 255)
    rect(sw/2+300, sh/2-150-100, 100, 100)
    fill(0, 0, 0, 255)
    rect(sw/2+300+5, sh/2-150+5-100, 90, 90)
    sprite("Cargo Bot:Command Left", sw-160, sh/2-200)
    end
    
    if GAME_STATE == m then
    background(91, 45, 81, 255)
    fontSize(25)
    font("Baskerville-Italic")
    fill(255, 255, 255, 255)
    text(ore..", "..dir1, sw/2, sh/2+100)
    --StopSpin
    fill(196, 196, 196, 255)
    rect(sw/2+60, sh/2-150-100, 100, 100)
    fill(255, 0, 0, 255)
    rect(sw/2+60+5, sh/2-150+5-100, 90, 90)
    --Spin
    fill(196, 196, 196, 255)
    rect(sw/2-60-100, sh/2-150-100, 100, 100)
    fill(1, 255, 0, 255)
    rect(sw/2-60-100+5, sh/2-150+5-100, 90, 90)
                --Back Button
    fill(196, 196, 196, 255)
    rect(sw/2+300, sh/2-150-100, 100, 100)
    fill(0, 0, 0, 255)
    rect(sw/2+300+5, sh/2-150+5-100, 90, 90)
    sprite("Cargo Bot:Command Left", sw-160, sh/2-200)
    end
    
    if GAME_STATE == l then
    background(91, 45, 81, 255)
    fontSize(thirfont)
    font("Baskerville-Italic")
    fill(255, 255, 255, 255)
    text(dice, sw/2, sh/2+100)
    --StopSpin
    fill(196, 196, 196, 255)
    rect(sw/2+60, sh/2-150-100, 100, 100)
    fill(255, 0, 0, 255)
    rect(sw/2+60+5, sh/2-150+5-100, 90, 90)
    --Spin
    fill(196, 196, 196, 255)
    rect(sw/2-60-100, sh/2-150-100, 100, 100)
    fill(1, 255, 0, 255)
    rect(sw/2-60-100+5, sh/2-150+5-100, 90, 90)
                --Back Button
    fill(196, 196, 196, 255)
    rect(sw/2+300, sh/2-150-100, 100, 100)
    fill(0, 0, 0, 255)
    rect(sw/2+300+5, sh/2-150+5-100, 90, 90)
    sprite("Cargo Bot:Command Left", sw-160, sh/2-200)
    end
    
    if a == 200 then
    background(91, 45, 81, 255)
    fill(255, 255, 255, 255)
    text(aa, sw/2, sh/2+80)
    text(bb, sw/2, sh/2+160)
    text(cc, sw/2, sh/2-0)
    text(dd, sw/2, sh/2-80)
    end
    --touch stuff
    --taptoplay
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-145 and CurrentTouch.y < sh/2-145+90 and GAME_STATE == a then
    GAME_STATE = z
    end
    ------------
    --cards
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-100+5+200 and CurrentTouch.y < sh/2-100+5+200+90 and GAME_STATE == b then
    GAME_STATE = c
    end
    --generator
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-100+5 and CurrentTouch.y < sh/2-100+5+90 and GAME_STATE == b then
    GAME_STATE = d
    end
    --guide
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-100+5-200 and CurrentTouch.y < sh/2-100+5-200+90 and GAME_STATE == b then
    GAME_STATE = e
    end
    ------------
    --one disk
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-100+5+200 and CurrentTouch.y < sh/2-100+5+200+90 and GAME_STATE == d then
    GAME_STATE = j
    end
    --reshuffle
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-100+5 and CurrentTouch.y < sh/2-100+5+90 and GAME_STATE == d then
    GAME_STATE = d
    end
    --roll of a dice
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-100+5-200 and CurrentTouch.y < sh/2-100+5-200+90 and GAME_STATE == d then
    GAME_STATE = l
    end
    ------------
    --good
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-100+5+400-50 and CurrentTouch.y < sh/2-100+5+400-50+90 and GAME_STATE == c then
    GAME_STATE = f
    country = country
    land = country
    poss = poss
    object = poss
    bmessage = bmessage
    cmessage = bmessage
    gconseq = gconseq
    gending = gconseq
    econseq = econseq
    eending = econseq
    rconseq = rconseq
    rending = rconseq
    wconseq = wconseq
    wending = wconseq
    end
    --right
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-100+5+200-50 and CurrentTouch.y < sh/2-100+5+200-50+90 and GAME_STATE == c then
    GAME_STATE = g
    country = country
    land = country
    poss = poss
    object = poss
    ~~~

scrap part 2:

bmessage = bmessage
    cmessage = bmessage
    gconseq = gconseq
    gending = gconseq
    econseq = econseq
    eending = econseq
    rconseq = rconseq
    rending = rconseq
    wconseq = wconseq
    wending = wconseq
    end
    --wrong
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-100+5-50 and CurrentTouch.y < sh/2-100+5-50+90 and GAME_STATE == c then
    GAME_STATE = h
    country = country
    land = country
    poss = poss
    object = poss
    bmessage = bmessage
    cmessage = bmessage
    gconseq = gconseq
    gending = gconseq
    econseq = econseq
    eending = econseq
    rconseq = rconseq
    rending = rconseq
    wconseq = wconseq
    wending = wconseq
    end
    --evil
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-100+5-50-200 and CurrentTouch.y < sh/2-100+5-50-200+90 and GAME_STATE == c then
    GAME_STATE = i
    country = country
    land = country
    poss = poss
    object = poss
    bmessage = bmessage
    cmessage = bmessage
    gconseq = gconseq
    gending = gconseq
    econseq = econseq
    eending = econseq
    rconseq = rconseq
    rending = rconseq
    wconseq = wconseq
    wending = wconseq
    end
    ------------
    --what is it
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-100+5+400-50 and CurrentTouch.y < sh/2-100+5+400-50+90 and GAME_STATE == e then
    GAME_STATE = k
    end
    --how to play
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-100+5+200-50 and CurrentTouch.y < sh/2-100+5+200-50+90 and GAME_STATE == e then
    GAME_STATE = b
    end
    --victory
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530 
    and CurrentTouch.y > sh/2-100+5-50 and CurrentTouch.y < sh/2-100+5-50+90 and GAME_STATE == e then
    GAME_STATE = b
    end
    --aligning rings
    if CurrentTouch.x > sw/2-265 and CurrentTouch.x < sw/2-265+530
    and CurrentTouch.y > sh/2-100+5-50-200 and CurrentTouch.y < sh/2-100+5-50-200+90 and GAME_STATE == e then
    GAME_STATE = b
    end
    ------------
    --spin and stahp one disk
    if CurrentTouch.x > sw/2-60-100 and CurrentTouch.x < sw/2+-60-100+90
    and CurrentTouch.y > sh/2-150+5-100 and CurrentTouch.y < sh/2-150+5-100+90 and GAME_STATE == j then
    ore = math.random(8)
    dir1 = math.random(4)
    elseif CurrentTouch.x > sw/2+60 and CurrentTouch.x < sw/2+60+90
    and CurrentTouch.y > sh/2-150+5-100 and CurrentTouch.y < sh/2-150+5-100+90 and GAME_STATE == j then
    ore = ore
    dir1 = dir1
    else
    
    end
    if dir1 == 1 or dir1 == 2 then
      dir1 = "Clockwise"
    elseif dir1 == 3 or dir1 == 4 then
    dir1 = "Anti-Clockwise"
  end
    ------------
    --spin and stahp reshuffle
    if CurrentTouch.x > sw/2-60-100 and CurrentTouch.x < sw/2+-60-100+90
    and CurrentTouch.y > sh/2-150+5-100 and CurrentTouch.y < sh/2-150+5-100+90 and GAME_STATE == j then
    ore = math.random(8)
    elseif CurrentTouch.x > sw/2+60 and CurrentTouch.x < sw/2+60+90
    and CurrentTouch.y > sh/2-150+5-100 and CurrentTouch.y < sh/2-150+5-100+90 and GAME_STATE == j then
    ore = ore
    else
    
    end
    ------------
    --spin and stahp roll of a dice
    if CurrentTouch.x > sw/2-60-100 and CurrentTouch.x < sw/2+-60-100+90
    and CurrentTouch.y > sh/2-150+5-100 and CurrentTouch.y < sh/2-150+5-100+90 and GAME_STATE == l then
    dice = math.random(6)
    elseif CurrentTouch.x > sw/2+60 and CurrentTouch.x < sw/2+60+90
    and CurrentTouch.y > sh/2-150+5-100 and CurrentTouch.y < sh/2-150+5-100+90 and GAME_STATE == l then
    dice = dice
    else
    
    end

Apologies for the masses of code - dunno how to do spoilers or things on this forum
If you don’t mind it and want to make sense of the code in a not so shabby form I can attach the old version if so desired

A few comments

Labelling events a,b,c instead of with recognisable names will make it hard to maintain and easy to make mistakes. I prefer something like this

states={Menu=1,Begun=2,Playing=3,End=4,Leaderboard=5}
settings={
    beginning= 1 , 
    menu = 2,
    good = 3,
    reshuffle = 4,
    --etc
}

Also I would redo the materials code like this

material={'carrots','gold', 'iron','grain',  --etc etc }
--now see how easy it is to choose one
poss = material[math.random(16)]

I would do the same with countries and consequences. You should try to get your draw function down to a handful of lines.

Your game state code has a lot of repetition. I would have this

--use local variables to store calculations you use repeatedly
--it is more efficient ands makes the code more readable
local x1,x2= sw/2-265,sw/2-265+530
local y1,y2=sh/2-100+5-50,sh/2-100+5-50+90
--what is it
ChangeState(x1,x2,y1+400,y2+400,e,k)
 --how to play
ChangeState(x1,x2,y1+200,y2+200,e,b)
--victory
ChangeState(x1,x2, y1+5,y2,e,b)
--and so on

using this function

function ChangeState(x1,x2,y1,y2,s1,s2)
    if GAME_STATE==s1 and
    CurrentTouch.x>x1 and CurrentTouch.x<x2 and
    CurrentTouch.y>y1 and CurrentTouch.y2<y2 then
    GAME_STATE=s2
end

thank you for the feedback.
Will indent and make it all nice to read before repost the updated code.

Right now I am shifting everything into draw calls in classes - still get the flickering.

Would any part of that fix the flickering error in particular?

I can no longer do the tap multiple times fix due to removing access to menu buttons on any other screen.

IMHO, the flickering is not the problem. The problem is that it is so difficult to find the cause.

I think there are several reasons for this.

  1. Your code is sprawling and messy, making it extremely difficult to debug - so I’m not even going to attempt to make sense of it - my suggestions above show some things you can do to reduce this, either by using tables to store things like parameters, or writing helper functions to do the repetitive work.

  2. You are attempting far too much in one go

If you build your app slowly and methodically, adding a little at a time, then you won’t get difficult debugging problems like this - because you know that any problem has to be caused by the few lines you added since the last successful run. This is (I believe) the principle of rapid programming - add a little, test, and repeat.

Whereas, if you add a whole lot of code at once, you give yourself big headaches.

If you have no choice but to work with a lot of untested code, eg you are converting code from somewhere else, then I suggest you divide and conquer. What I mean is find ways to turn off parts of the app, eg by commenting out chunks or putting in if tests that disable bits of the app. You need to isolate the specific lines that are causing the problem, so make this easier by focussing on small parts of the app. Or extract some key lines that may be the cause, put them in a little test app on their own, and see if you can replicate the problem.

(I do this all the time, although I usually do it the other way. When I add a new function, I test it in a little app on its own before putting it into the main app).

But I think the key to solving your problem lies in simplifying your code, and testing it a bit at a time, as you add to it. You will still have puzzling problems from time to time, but you will greatly reduce the annoying mystery errors that turn out to be a one letter typo somewhere.

wrt flickering, that is most likely due to your rapidly changing what is drawn, so I would start by disabling the lines that change state (or whatever controls changes to what is drawn). If that solves the problem, then you can examine why it is changing so rapidly.

the flickering only started occuring when I moved things into class draws that i call. I think the problem lies in it isn’t flickering fast enough to get 30fps or it is fighting the menu screen, neither of which I know how to fix. Is there some clear screen line I could put in before it runs each new class? I tried having a new background put in but that was to no effect.

Would it maybe have to do with the draw function running inside a touch function?

the draw function is running inside what? :open_mouth:

The draw function should draw the screen. The touched function can change what is drawn, but draw should always draw it. No wonder it is flickering.

okay.
what I meant by that is,
the call for the draw occurs inside the touch function, but the shapes are still drawn by the draw. if that is still bad, which i suspect it is, I don’t know how to move it outside of the function. Will have another crack at it though

All fixed! Thanks a bunch for your help and feedback so far :))

You will do better to set a variable in touch, if you want something drawn. Then the main draw function can test that variable and draw it.

@OwenClaxton - if all those rect commands are making some kind of grid or shape which is the same every frame, you may be better (as part of setup) to create an image in memory, sprite all the rects onto it (with setContext) to create the shape in a single image, then all you do in draw is simply sprite that one image, instead of all that drawing code. Much faster, much neater.

If you do this, put all the code that creates the image into a separate function, so all you write in setup is CreateGrid(), keeping things very tidy and making it easy to test (because you can take your new function off to a little test app and see if it works before including it).