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?

This is a discussion on Lua Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Originally Posted by N0obKi|l3r.exe im about to commit suicide from stupidity last question: how can i make a random number ...

 Tweet
1. Originally Posted by N0obKi|l3r.exe
im about to commit suicide from stupidity last question:

how can i make a random number load... i.e a number bettween 1 and 3 eighter 1, 2, or 3 ?
Put math.randomseed(os.time() ) as the first line. Then do:
math.random(low, high)
You could just do mynumber = math.random(low,high)

Hope I helped. :)

2. myNumber = math.random(1,30)

This picks a number at random between 1 and 30.If you put this BEFORE your main loop, it will pick a random number once, when the script is first started. If you put this AFTER your main loop, it will pick a new number each time the loop performs.

Also, if you are going to be using random numbers, put this at the beggining of your code:

math.randomseed(os.time() )

Without this, it would pick the same random number every time, which wouldn't make it very random.

EDIT: Oops, looks like PSPduh already helped you. BTW- Don't worry about making stupid mistakes, everyone does it.

3. Originally Posted by Access_Denied
myNumber = math.random(1,30)

This picks a number at random between 1 and 30.If you put this BEFORE your main loop, it will pick a random number once, when the script is first started. If you put this AFTER your main loop, it will pick a new number each time the loop performs.

Also, if you are going to be using random numbers, put this at the beggining of your code:

math.randomseed(os.time() )

Without this, it would pick the same random number every time, which wouldn't make it very random.

EDIT: Oops, looks like PSPduh already helped you. BTW- Don't worry about making stupid mistakes, everyone does it.
Yes but yours is much more explained then mine. :)

4. Originally Posted by PSPduh
Yes but yours is much more explained then mine. :)
That's probably why you posted before me, I took too long to write it.:)

5. thnaks both off you. now with this im going top make it so thaty after 5 seconds, it will load a number. if number == 1 then health = health - 5 and restart timer and start it. iff 2 then do nothing what do ya think? fighting games are confusong thnx to all who hasve helped!

6. You could do something like this:

if number == 1 then
health = health - 5
counter:reset(0)
counter:start()
end

7. i know i did i was just tellin waht i was gonna do i9 did:

if counter:time() > 4000 then
mynumber = math.random(1,1000)
screenrint(30,30,"num".. mynumber,black)
counter:reset(0)
counter:start()
end

if mynumber == 2 then
Health = Health - 5
end
-= Double Post =-
damn. while it waits for the timer to laod up to 4000,,, it like subtract 5 every sec of it... sdo im sticking to 1000

8. OK, I just downloaded TTLDE v 2.1. I have tried it using the widows emulator and it works fine. But, when I go into my other program and write "dofile("TTLDE.lua")" in the windows emulator, I get all kinds of errors. But when I run it alone, it works fine. Does anyone know why? And yes, I have all the files in the same directory.
-= Double Post =-
Sorry for bumping this so quickly, but I need an answer ASAP.

9. The error names would help immensly ;)

10. Nevermind, I'm done with that problem. But now I need to know, How many images can you load in one script in LuaPlayer?

11. Im in need of a little bit of help. Im having problems getting my start menu working the way it should. What im trying to do is, after you press start to bring up the startmenu pressing start again should make it go away.. this can work using the break function to make the start menu go away instead of the whole script but i still need to know what to put to make it use the start button after it has allready been pressed to bring it up. Heres my code.
Code:
```if pad:start() then
while true do
screen:clear()
screen:blit(0,0,board)
sel=sel-1
sel=sel+1
end
if sel<1 then sel=4 end
if sel>4 then sel=1 end
local choice={"Save","Save & Quit","Quit","Cancel"}
local chcol={editcolor,editcolor,editcolor,editcolor}
chcol[sel]=selecolor
screen:blit(190,106,start)
screen:print(224,117,choice[1],chcol[1])
screen:print(196,127,choice[2],chcol[2])
screen:print(224,137,choice[3],chcol[3])
screen:print(216,147,choice[4],chcol[4])
if sel==1 or sel==2 then
local file=io.open("./memos/"..field,"w")
file:write(field2)
file:close()
end
if sel==2 or sel==3 then
goprg = false
end
break
end

screen.waitVblankStart()
screen:flip()
end```
i have got this to work the way i want by simply using

Code:
```if pad:circle() then
break
end```
but, circle is not the buton i want to use, its start that i need.

and another question i have is, how do i make it so pressing circle makes this only select once instead of switching back and forth real fast..

Code:
```elseif pad:circle() then
if fieldedit == 1 then fieldedit = 2
else                   fieldedit = 1
end```
what that does it when you press ( and hold ) circle it switches between the two really fast and makes it hard to select. i need to know how to make it only switch once per time your press circle.

Put this above your "while true do":

Put this under it if you haven't already

now change "if pad:circle()" to this

This will make it so it only changes once when you press circle.
-= Double Post =-
Wait, I know the ansere to your first question. You used the start button in your main loop. But you didn't use it in your pause function. So you can just do this

break
end

Not doing this would make it pause and unpause very quickly.

13. Originally Posted by Branin
Im in need of a little bit of help. Im having problems getting my start menu working the way it should. What im trying to do is, after you press start to bring up the startmenu pressing start again should make it go away.. this can work using the break function to make the start menu go away instead of the whole script but i still need to know what to put to make it use the start button after it has allready been pressed to bring it up. Heres my code.
Code:
```if pad:start() then
while true do
screen:clear()
screen:blit(0,0,board)
sel=sel-1
sel=sel+1
end
if sel<1 then sel=4 end
if sel>4 then sel=1 end
local choice={"Save","Save & Quit","Quit","Cancel"}
local chcol={editcolor,editcolor,editcolor,editcolor}
chcol[sel]=selecolor
screen:blit(190,106,start)
screen:print(224,117,choice[1],chcol[1])
screen:print(196,127,choice[2],chcol[2])
screen:print(224,137,choice[3],chcol[3])
screen:print(216,147,choice[4],chcol[4])
if sel==1 or sel==2 then
local file=io.open("./memos/"..field,"w")
file:write(field2)
file:close()
end
if sel==2 or sel==3 then
goprg = false
end
break
end

screen.waitVblankStart()
screen:flip()
end```
i have got this to work the way i want by simply using

Code:
```if pad:circle() then
break
end```
but, circle is not the buton i want to use, its start that i need.

and another question i have is, how do i make it so pressing circle makes this only select once instead of switching back and forth real fast..

Code:
```elseif pad:circle() then
if fieldedit == 1 then fieldedit = 2
else                   fieldedit = 1
end```
what that does it when you press ( and hold ) circle it switches between the two really fast and makes it hard to select. i need to know how to make it only switch once per time your press circle.
to make the circle stop going insanely fast switching between its actions, just put "screen.waitVblankStart(1 0)" at the top of "end". (so its the last thing that the small loop does. thatll work.

as for pressing start, make the whole code under "if pad:start() then" a function.

then put:

Code:
```if pad:start() then
your-function-name-here()
end```
and to make it go back, in your new function, put "if pad:start() then break end".

there you go. : )

14. Can anyone tell me if string.gmatch is implemented in the latest version of LuaPlayer? It doesn't seem to have it in the Windows version.

(Note that I can't check since I don't have a PSP capable of homebrew. I am just trying to help someone else out).

15. Ok, iv tried what you have said but now pressing circle does nothing at all, no errors or a anything.

Code:
```screen:waitVblankStart(10)
screen:flip()
if fieldedit == 1 then fieldedit = 2
else                   fieldedit = 1
end
DisplayScreen()
screen:waitVblankStart()
screen:flip()
else
screen:waitVblankStart()
end
end
end
else
screen:waitVblankStart(10)
end
end```
above is the very end of my script.. can anyone tell me why pressing circle does nothing now.

16. You put this:

it should be

See the changes?

17. same thing bro, still does nothing.

[WiP] Assualt - BETA .1

Originally Posted by Access_Denied
You put this:

it should be

See the changes?
Doesn't matter, both lines are logically the same.
A ~= B is the same as B ~= A

19. Did you put in this line before your "while true do"?

20. If he didn't, it would crash since oldpad would be nil.

Try this:
Code:
```LastCircleKeyState = false;

while true do
-- blah blah

if not LastCircleKeyState then
-- do stuff
end
LastCircleKeyState = true;
else
LastCircleKeyState = false;
end
-- blah blah
end```

[WiP] Assualt - BETA .1

Doesn't matter, both lines are logically the same.
A ~= B is the same as B ~= A
Yes, but sometimes LUA isn't very logical.

22. altair: u told me how to find current fps, can u link tell me again?? i cant find the post tat u told me in. thx

23. I think altair is gone. He's coming back, but I think he's on vacation or something.

24. Originally Posted by Branin
Ok, iv tried what you have said but now pressing circle does nothing at all, no errors or a anything.

Code:
```screen:waitVblankStart(10)
screen:flip()
if fieldedit == 1 then fieldedit = 2
else                   fieldedit = 1
end
DisplayScreen()
screen:waitVblankStart()
screen:flip()
else
screen:waitVblankStart()
end
end
end
else
screen:waitVblankStart(10)
end
end```
above is the very end of my script.. can anyone tell me why pressing circle does nothing now.
wheres the first "if"?

25. Whats the best text editor to do lua code in? Im using notepad at the moment but whats the best program that checks your syntax as you type?

this doesnt do lua

27. RAWR -edited-

29. how do i make an image move using the arrow keys? my image is called "smiley" so some code would be nice :)

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 10:14 PM.

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