The above video goes away if you are a member and logged in, so log in now!

 Would you like to get all the newest Gaming News fromQJ.NET in your email each day? Want to learn more about the team who brings you the QJ news?

## Lua Random Function???

This is a discussion on Lua Random Function??? within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; is there a random fuction??? EXAMPLE: i would like it to pick a ARROW lets say it randomly picked Down ...

 Tweet
1. ## Lua Random Function???

is there a random fuction???
EXAMPLE:
i would like it to pick a ARROW lets say it randomly picked Down then i would hit down then the next thing it would do is Down ARROW then SOMTHING else then u copy that DOWN and LIKE UP

IS this Possible

2. So basicly you want a simon says game?

3. No such thing as random numbers in computers, but if you don't like the traditional
clock seed random function you could produce a pseudo random number by timing
how long the user holds down buttons with a counter.

4. Originally Posted by hb-man
is there a random fuction???
EXAMPLE:
i would like it to pick a ARROW lets say it randomly picked Down then i would hit down then the next thing it would do is Down ARROW then SOMTHING else then u copy that DOWN and LIKE UP

IS this Possible

Like
Code:
```math.randomseed(os.time())
function randomtest()
RandomAI=math.random(1,3)
end
RandomAI=math.random(1,3)
while true do
if RandomAI==1 then
screen:blit(0,0, down1)
score check here etc...
end
elseif RandomAI==2 then
screen:blit(0,0, up2)
score check here etc...
end
elseif RandomAI==3 then
screen:blit(0,0, cross3)
score check here etc...
end
end
end```
I Dont think it will work straight away because i haven't even
included image.load lol. But you'll need to add on to that etc...
This is more of an example code, based with random.math() and

I just woke up so i am sorry for the awfully coding etc. :icon_wink

5. Originally Posted by Gutya
So basicly you want a simon says game?
SHHH....thats what im making SHHHHH

lol

i have sound and backround and butttons done...

now i need to get some sorta random thing....i will try the one ABOVE me in 1 min hehe

6. Originally Posted by hb-man
SHHH....thats what im making SHHHHH

lol

i have sound and backround and butttons done...

now i need to get some sorta random thing....i will try the one ABOVE me in 1 min hehe
Good luck! ;)
I Hope you make a successfull release soon! :razz:
Dont forget, i just made that as an example.
It may or may not even work properly,
but you can still use some of the code without it crashing etc.

7. thats what i did....still try to get it to work..tho......
math.randomseed(os.time() )
function randomtest()
RandomAI = math.random(square, triangle, cross, circle)

end

RandomAI = math.random(square, triangle, cross, circle)
while true do
if RandomAI = square() then
screen:blit(0, 0, square1)

end

elseif RandomAI = triangle() then
screen:blit(0, 0, triangle2)

end

elseif RandomAI = cross() then
screen:blit(0, 0, cross3)

end

elseif RandomAI = circle() then
screen:blit(0, 0, circle4)

end

end

8. Code:
```--\\Image Load Test\\--

math.randomseed(os.time())

function randomtest()
RandomAI=math.random(1,3)
end

RandomAI=math.random(1,3)

while true do
if RandomAI==1 then
screen:blit(0,0, down1)
score check here etc...
end
elseif RandomAI==2 then
screen:blit(0,0, up2)
score check here etc...
end
elseif RandomAI==3 then
screen:blit(0,0, cross3)
score check here etc...
end
end
end```

9. THANK you for all the HELP so far....this is my first game SO thank yo...
I am having a problem in my code some where here it says

ERROR:index.lua153: `then' epected near `='

im not sure where that is....??

math.randomseed(os.time() )
function randomtest()
RandomAI = math.random(square, triangle, cross, circle)

end

RandomAI = math.random(square, triangle, cross, circle)
while true do

if RandomAI = square then
screen:blit(76, 110, square)

end

if RandomAI = triangle then
screen:blit(228, 34, triangle)

end

if RandomAI = x then
screen:blit(228, 207, x)

end

if RandomAI = circle then
screen:blit(375, 110, circle)

end

end

10. on your if statements, it needs to be == instead of =

you are also missing an extra 'end' on all your code chunks since you have 2 if statements in each

and your COMPLETELY using the random function wrong

math.random(low, high) will return a number between the low and the high number

put your images in a table and use the math.random function to find the index

11. Originally Posted by youresam
on your if statements, it needs to be == instead of =

you are also missing an extra 'end' on all your code chunks since you have 2 if statements in each

and your COMPLETELY using the random function wrong

math.random(low, high) will return a number between the low and the high number

put your images in a table and use the math.random function to find the index
THANK you...

edited

12. sorrry about the double post...

IM HAVING PROBLEMS still is it possible there is A Toturial ON THIS?????

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

All times are GMT -8. The time now is 08:09 AM.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY