Lua Programming Help Thread
This is a discussion on Lua Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Zitat von N0obKi|l3r.exe im about to commit suicide from stupidity last question: how can i make a random number load... ...
-
08-12-2006, 11:18 AM #3181QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Put math.randomseed(os.time() ) as the first line. Then do:
Zitat von N0obKi|l3r.exe
math.random(low, high)
You could just do mynumber = math.random(low,high)
Hope I helped. :)
-
08-12-2006, 11:19 AM #3182I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
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.
-
08-12-2006, 11:22 AM #3183QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Yes but yours is much more explained then mine. :)
Zitat von Access_Denied
-
08-12-2006, 11:26 AM #3184I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
That's probably why you posted before me, I took too long to write it.:)
Zitat von PSPduh

-
08-12-2006, 11:30 AM #3185Asleep...

- Registriert seit
- Oct 2005
- Beiträge
- 1.383
- Points
- 11.516
- Level
- 70
- Downloads
- 0
- Uploads
- 0
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!
-
08-12-2006, 11:35 AM #3186I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
You could do something like this:
if number == 1 then
health = health - 5
counter:reset(0)
counter:start()
end
-
08-12-2006, 11:57 AM #3187Asleep...

- Registriert seit
- Oct 2005
- Beiträge
- 1.383
- Points
- 11.516
- Level
- 70
- Downloads
- 0
- Uploads
- 0
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)
screen
rint(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 1000Geändert von N0obKi|l3r.exe (08-12-2006 um 11:57 AM Uhr) Grund: Automerged Doublepost
-
08-12-2006, 08:34 PM #3188I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
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.Geändert von Access_Denied (08-12-2006 um 08:34 PM Uhr) Grund: Automerged Doublepost

-
08-12-2006, 11:22 PM #3189words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
The error names would help immensly ;)

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
08-13-2006, 04:06 AM #3190I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Nevermind, I'm done with that problem. But now I need to know, How many images can you load in one script in LuaPlayer?

-
08-14-2006, 08:59 PM #3191Developer

- Registriert seit
- Jun 2006
- Ort
- USA, Virginia
- Beiträge
- 580
- Points
- 5.650
- Level
- 48
- Downloads
- 0
- Uploads
- 0
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.
i have got this to work the way i want by simply usingCode:if pad:start() then while true do screen:clear() screen:blit(0,0,board) pad=Controls.read() if pad:up() and oldpad:up()~=pad:up() then sel=sel-1 elseif pad:down() and oldpad:down()~=pad:down() then 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 pad:cross() then 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 background=Image.load("./images/background.png") tfread = false end break end screen.waitVblankStart() screen:flip() oldpad=pad end
but, circle is not the buton i want to use, its start that i need.Code:if pad:circle() then break end
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..
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.Code:elseif pad:circle() then if fieldedit == 1 then fieldedit = 2 else fieldedit = 1 end
-
08-14-2006, 09:47 PM #3192I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Well I don't feel like reading your code, so I won't answer your first question. But I'll answer you second one.
Put this above your "while true do":
oldpad = Controls.read()
Put this under it if you haven't already
pad = Controls.read()
Put this after your "screen.flip"
oldpad = pad
now change "if pad:circle()" to this
if pad:circle() and oldpad:circle() ~= pad:circle() then
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
if pad:start() then
break
end
But I would replace both of your "if pad:start()" with:
if pad:start() and oldpad:start() ~= pad:start() then
Not doing this would make it pause and unpause very quickly.Geändert von Access_Denied (08-14-2006 um 09:47 PM Uhr) Grund: Automerged Doublepost

-
08-15-2006, 12:26 AM #3193QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
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.
Zitat von Branin
as for pressing start, make the whole code under "if pad:start() then" a function.
then put:
and to make it go back, in your new function, put "if pad:start() then break end".Code:if pad:start() then your-function-name-here() end
there you go. : )[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
08-15-2006, 03:49 AM #3194QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
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).
-
08-15-2006, 08:36 AM #3195Developer

- Registriert seit
- Jun 2006
- Ort
- USA, Virginia
- Beiträge
- 580
- Points
- 5.650
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Ok, iv tried what you have said but now pressing circle does nothing at all, no errors or a anything.
above is the very end of my script.. can anyone tell me why pressing circle does nothing now.Code:screen:waitVblankStart(10) screen:flip() pad = Controls.read() elseif pad:circle() and pad:circle() ~= oldpad:circle() then 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 oldpad = pad end
-
08-15-2006, 08:41 AM #3196I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
You put this:
elseif pad:circle() and pad:circle() ~= oldpad:circle() then
it should be
elseif pad:circle() and OLDpad:circle() ~= PAD:circle() then
See the changes?
-
08-15-2006, 08:55 AM #3197Developer

- Registriert seit
- Jun 2006
- Ort
- USA, Virginia
- Beiträge
- 580
- Points
- 5.650
- Level
- 48
- Downloads
- 0
- Uploads
- 0
same thing bro, still does nothing.
-
08-15-2006, 09:01 AM #3198QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Someone else had a similar problem using oldpad:
[WiP] Assualt - BETA .1
Doesn't matter, both lines are logically the same.
Zitat von Access_Denied
A ~= B is the same as B ~= A
-
08-15-2006, 09:02 AM #3199I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Did you put in this line before your "while true do"?
oldpad = Controls.read()
-
08-15-2006, 09:05 AM #3200QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
If he didn't, it would crash since oldpad would be nil.
Try this:
Code:LastCircleKeyState = false; while true do -- blah blah pad = Controls.read(); if pad:circle() then if not LastCircleKeyState then -- do stuff end LastCircleKeyState = true; else LastCircleKeyState = false; end -- blah blah end
-
08-15-2006, 09:16 AM #3201I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Yes, but sometimes LUA isn't very logical.
Zitat von head_54us
Geändert von Access_Denied (08-15-2006 um 09:33 AM Uhr)

-
08-15-2006, 12:54 PM #3202Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
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
--------------------------------------------------------------------------------------
-
08-15-2006, 12:57 PM #3203I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
I think altair is gone. He's coming back, but I think he's on vacation or something.

-
08-16-2006, 01:02 AM #3204QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
wheres the first "if"?
Zitat von Branin
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
08-16-2006, 02:30 AM #3205QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
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?
...Just Returned To The Scene...
-
08-16-2006, 03:39 AM #3206Developer

- Registriert seit
- Oct 2005
- Ort
- Dubuque
- Beiträge
- 423
- Points
- 12.154
- Level
- 72
- My Mood
-
- Downloads
- 1
- Uploads
- 0
-
08-16-2006, 04:31 AM #3207QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
this doesnt do lua
Zitat von jsharrad
...Just Returned To The Scene...
-
08-16-2006, 04:33 AM #3208
RAWR -edited-
Geändert von Urza the Tyrant (08-16-2006 um 04:54 AM Uhr)
-
08-16-2006, 04:39 AM #3209Developer

- Registriert seit
- Oct 2005
- Ort
- Dubuque
- Beiträge
- 423
- Points
- 12.154
- Level
- 72
- My Mood
-
- Downloads
- 1
- Uploads
- 0
oops, wrong link :)
notepad2 again. :P
-
08-16-2006, 09:30 AM #3210QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
how do i make an image move using the arrow keys? my image is called "smiley" so some code would be nice :)
...Just Returned To The Scene...


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum