thanks it's working now, i knew it was an issue with matched being updated too many times but i had been staring at it so long yesterday i just couldnt focus... came back at it now and instantly fix it, you were kinda right except i have it running outside of the E press code (because the timer needs to run far longer than the actual key is pressed for)
but with a simple varible to stop the for loop being run again it now works
i originally was trying a "break" function thinking that would do the same but now i realise that it wouldnt.
if anyone is interested the working code is here
picknumber = {}
drawn = {}
matched = 0 ; checked = 0;
function gamblebox_main(e)
local this = aEntity:new(e, "gamblebox")
local resultTimer = aTimer:new(e, 7) --countdown from 6
if this:distance(aPlayer) < 100 and pressed == 0 then
Prompt("Gamble Box, *Press E to play*")
if g_KeyPressE == 1 then
pressed = 1; playing = 1; resultTimer:start()
--get 3 random numbers for player
for PN = 1, 3 do
picknumber[PN] = math.random(1,30)
end --end for PN
--draw 5 winning numbers
for WN = 1, 5 do
drawn[WN] = math.random(1,30)
if WN > 1 then
for N = 1, WN-1 do
if drawn[WN] == drawn[N] then
drawn[WN] = math.random(1,30)
end --end if repeat
end --end for N
end --end if WN > 1
end --end for WN
end --end input check
end --end dis
if playing == 1 then
if resultTimer:left() >= 4 then
Prompt("Numbers picked = " .. picknumber[1] .. " , " .. picknumber[2] .. " , " .. picknumber[3] .. " : winning numbers = " .. drawn[1] .. " , " .. drawn[2] .. " , " .. drawn[3] .. " , " .. drawn[4] .. " , " .. drawn[5])
end --end timer left >= 4
if resultTimer:left() < 4 then
if checked == 0 then
for WN = 1, 5 do
if picknumber[1] == drawn[WN] or picknumber[2] == drawn[WN] or picknumber[3] == drawn[WN] then
matched = matched + 1
end --end check pick 1
end --end for WN
checked = 1
end --end check matches
if matched == 0 then
Prompt("No matches this time, Next try half price!")
end
if matched == 1 then
Prompt("Only 1 match, better luck next time")
end --end matched 1
if matched == 2 then
Prompt("So close... 2 matches, maybe 1 more try? :) ")
end --end matched 2
if matched == 3 then
Prompt("***WINNER!*** 500 Credits Awarded")
end --end matched 3
end --end timer < 4
if resultTimer:left() < 1 then
playing = 0; matched = 0; pressed = 0; checked = 0;
resultTimer:reset(); resultTimer:stop()
end --end of timer
end --end playing check
end --end func
i'm hoping to be able to change the input system (so you can actually pick the first set of numbers yourself) next update
and i haven't worked out a way to stop repeats in the numbers yet (i was hoping to use a goto to make it restart the randoming process but goto doesnt work afaik) so for now it just randoms the repeat number once more (but doesnt check it again so it's possible that it'll be a repeat again anyway)
i will also be adding in a cost varible (hence the half price prompt) but that shouldn't be too tough to add (the tough part will be working out the right balance for cost / reward).
life's one big game
windows vista ultimate
i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11