Saturday, 15 June 2013

table - Lua - math.random () isn't working -



table - Lua - math.random () isn't working -

in origin of programme initialise random number generator with:

math.randomseed (os.time ()) math.random (); math.random (); math.random ()

in function, want phone call math.random when variable pc has value of nil:

function playervspc2 () if pc == nil pc = math.random (1, 7) end end

this give random number, repeats number when playervspc2 called 1 time again during runtime:

while win == 0 playervspc1 () windetect (playername) if win == 1 break end playervspc2 () windetect ("the pc") end

when math.random called without status pc == nil, gives random numbers. have checked pc nil before the if pc == nil statement starts.

i sec phone call function doesn't anything, pc (which global value, not nil anymore, instead has value randomly generated first time, status if pc == nil false , nil happens. alter to

function playervspc2 () pc = math.random(1,7) end

and provide random pc every time phone call it.

table random lua

No comments:

Post a Comment