could i see the section of code that that part is in, and the table that the data is being loaded from again, as it is in the script
Printable View
could i see the section of code that that part is in, and the table that the data is being loaded from again, as it is in the script
Okay.
That's the heart of it. It's taken from throughout the entire script but hopefully it makes sense. I can give you the whole thing if you want, but it's probably not necessary.Code:locations = {}
while true do
pad = Controls.read()
screen:clear()
dx = pad:analogX()
dy = pad:analogY()
if gamestate == "game" then
if locations ~= nil then
for i = 1, table.getn(locations) do
screen:blit(locations[i].x,locations[i].y,dot)
end
end
elseif gamestate == "menu" then
pad = Controls.read()
--if user is loading... took that out for this example
if pad:square() and not oldpad:square() then
System.usbDiskModeDeactivate()
loadFile = io.open("Saved Sets/" .. loadFile2 .. ".txt","r")
number = 0
for line in loadFile:lines() do
number = number + 1
end
for j = 1, math.floor(number/2)*2, 2 do
xc = loadFile:read()
yc = loadFile:read()
table.insert(locations,{x=xc,y=yc})
end
loadFile:close()
System.usbDiskModeActivate()
gamestate = "game"
pausestate = "select"
end
end
end
hmm you know this part
could you check for me by printing the data to the screen before continuing what these are, because i think that what you are doing is thisCode:xc = loadFile:read()
yc = loadFile:read()
so calling a screen:blit() with those valuse it is causing the loop in gettable error where 4, 10 is the valueCode:xc = 4, 10
yc = 4, 10
also try using the code that i made for you it does work, it loads and saves files easier, and you wouldnt get that error
if what i said is the case then it would be easier to use the code that i made that i know works, than to recode what you have to work, because it isnt the right way to load data from a table anyway, not saying mine is the right way but it is better than the current method that you are using
thanks
Printing them told me that they were nil. But I used the way you showed me a few posts ago, and it worked like a charm. Thanks a lot!
Zitat:
Zitat von andyauff
You are still not reading the file correctly.
loadFile:read() is returning "x,y", correct? (where x and y are the co-ordinates in each case) So, you are basically stating:
Even if you stated:Code:xc = "x,y"
yc = "x,y"
It still wouldn't work because Lua cannot convert "x,y" (A string) into a group of numbers.Code:xc,yc = "x,y"
You would need something like this:
But even that wouldn't work because you are just reading the the first line over and over, you need to move forward a line every time. So you would need something like this: (I'm not sure what the for loop looping through in your code, but this is general)Code:loc = loadFile:read()
xc = string.sub(loc,1,string.find(loc,",") - 1)
yc = string.sub(loc,string.find(loc,",") + 1)
EDIT: Oh, I see. You are iterating in groups of 2, so your files are just stored as a list of numbers. in that case:Code:if pad:square() and not oldpad:square() then
for line in io.lines("Saved Sets/" .. loadFile2 .. ".txt") do
table.insert(locations,{x=string.sub(line,1,string.find(line,",") - 1),y=string.sub(line,string.find(line,",") + 1)})
end
System.usbDiskModeDeactivate()
System.usbDiskModeActivate()
gamestate = "game"
pausestate = "select"
end
Or if you are adding to an existing list:Code:local n = 0
for line in io.lines("Saved Sets/" .. loadFile2 .. ".txt") do
n = n + 1
if math.floor(n / 2) * 2 == n then
locations[n / 2 + 1].y = line
else
locations[(n - 1) / 2 + 1] = {x = line}
end
end
Code:local p = table.getn(locations)
local n = 0
for line in io.lines("Saved Sets/" .. loadFile2 .. ".txt") do
n = n + 1
if math.floor(n / 2) * 2 == n then
locations[p + n / 2 + 1].y = line
else
locations[p + (n - 1) / 2 + 1] = {x = line}
end
end
no problem, glad it workedZitat:
Zitat von andyauff
I see what you mean, but that would be if I had the x and y values on the same line in the file. The way I had it was an x value on the first line, y on the second, x on the third, y on the fourth, etc. But I'm using a completely different method now, thanks to FaT3oYCG, so it's all good. But thanks :).Zitat:
Zitat von Nielkie
I updated my post when I saw what the for loop was doing. Anyway, it's always nice to know the reason for a problem.Zitat:
Zitat von andyauff
Okay, thanks Nielkie. Yes, I agree, it is certainly important to understand the problem.Zitat:
Zitat von Nielkie
hey would anyone know how to get a decimal converted to a whole number ?
for example i get 88.3333333333333 but i want it to print 88
math.floor(83.33333333333 33)
I'm pretty sure that's it.
thanks andyauff :]]
No problem.
oops ill put this in in just a moment
EDIT: there you go
if the number after the decimal is smaller than 5 then it will round down like it would in propper maths and if it is 5 or above then it will round upCode:function round_number(number)
check_number_full = string.format("%.1f", number)
check_number_single = string.sub(check_number_full, -1)
if check_number_single < 5 then
return math.floor(number)
else
return math.ceil(number)
end
end
e.g. 5.27577 woud return 5 and 5.78435 would return 6
Yeah, I thought there was a function for rounding up too. That's why I said I was pretty sure. math.floor worked because you were rounding down. Thanks for adding that function, FaT3oYCG.
thanks :]Zitat:
Zitat von FaT3oYCG
the math.floor worked for me but its always good to see exactly how it works thanks
yeah i just though id put that in because it can be used all the time, ill explain the functions for you aswell
math.floor(number) - all this does is remove any decimals on the number after the point, to return the whole number
math.ceil(number) - all this does is add one to the number and then remove any decimals after the point, to return a whole number
i made that function because it rounds depending on the decimal not by just rounding up or down all of the time
Wow. That is a horrible rounding function, and you explained what math.floor and ceil do incorrectly. For negative numbers, your explanation no longer holds true.
Also, nonsucky rounding function:
Code:function math.round(n)
return math.floor(n+0.5)
end
Doesn't math.floor round down to the nearest whole number and math.ceil round up?
yes but the way he just wrote it is that it adds .5 to any of ur decimals and rounds down... so if ur deciam is say 1.5 it would be 1.5 +.5 witch = 2 and 2 rounds to 2... if it were 1.3 then it would be 1.3 +.5 witch = 1.8 witch with math.floor would round to 1 so..it still works :P cool and simple rounding function :}]]Zitat:
Zitat von michaelp
michaelp - yes. that would be what it does. please refer to above posts (although incorrect it still gets the point across) and http://lua-users.org/wiki/TutorialDirectory before asking more questions.
lol
everyday when im walking down the street, every turtle that i meet says, its a simple message and it comes from the shell, you help people and then i pwn you, hey!!!. every day when im ...
thanks lol
yeah my function sux, but i did make it a long time ago
oh and
math.floor (x)
Returns the largest integer smaller than or equal to x.
math.ceil (x)
Returns the smallest integer larger than or equal to x.
CAn someone can show me how to use this function in he Lua Player HM.
System.usbDevUMD()
If I try it like that :
if pad:cross() then
System.usbDevUMD()
end
Nothing happen when i push X. CAn someone help me please.
System.usbDevUMD() sets the usb to the umd
System.diskModeActivate() still turns it on so
if pad:cross() then
System.usbDevUMD()
System.diskModeActivate()
end
Attemp to call field 'diskmodeActivate" (a nil value)
Do you know what does that means ?
sorry
System.usbDiskModeActivat e()
Thanks. For the fastest with anwser me. What abotu that one.
I'll want to creat a drum app. I wnt to load my sound and associate them to a name. Then I want to, if i push X, per exemple, play the sound associate to "kick" bu tonly once. Do u know how i have to do that.
I alerdy try but i wasn'n able.
you need to put
oldpad = Controls.read()
at the top of your code by like the colors, or what not and put
if pad:cross() and oldpad:cross() ~= pad:cross() then
before the sound you want to be heard
and finally right before the end of your code put
oldpad=pad
that should work, Please correct me if I'm wrong Fat3oYCG
also I think your idea sounds cool, keep up the good work
PSProgrammer - that gets the job done, but personally I believe it is a horrible way to accomplish that job.
Replace:
with:Code:pad = Controls.read()
and then for button press detection, use:Code:oldpad = pad
pad = Controls.read()
Basically, that will make the logic of it say, if cross has been pressed but it was not pressed last loop (aka it JUST got pushed down) then blahCode:if pad:cross() and not oldpad:cross() then
If you want to change that logic to, if cross was pressed down but just got released then blah, then do this:
Code:if oldpad:cross() and not pad:cross() then
TurtlesPwn - that gets the job done, but personally I believe it is a horrible way to accomplish that job.
Replace:
with:Code:Dpad = Controls.read()
and then for button press detection, use:Code:oldDpad = Dpad
Dpad = Controls.read()
Basically, that will make the logic of it say, if cross has been pressed but it was not pressed last loop (aka it JUST got pushed down) then blahCode:if Dpad:cross() and not oldDpad:cross() then
If you want to change that logic to, if cross was pressed down but just got released then blah, then do this:
Think about this before responding.Code:if oldDpad:cross() and not Dpad:cross() then
no because the dpad is not the triangle, square, circle, cross, l, r, start, select, home, note, screen, vol up, vol down or analougue buttons it is the directional pad
Yeah, sry turtlesPwN I didn't think of that last night, thanks for improving it
-= Double Post =-
By the way, i don't know if any of you have seen my post, but I am in need for some grafix artists,and/or a co programer for a Zelda game I'm working on in lua. PM me if your interested, or just reply on this thread
Umm, klepto, what exactly was wrong with how I did it, and what exactly did you fix? Nothing?
edit: oops typo what->was
yeah like i said i would also like to add that people use the word pad and oldpad because it is quicker to do instead of typing the whole thing every time using Dpad just makes it take longer it has an extra letter and you have to press the shift key even if it was all in lowercse it would still be wrong because every button on the psp is not the Dpad it is the controls hence Controls.read() incase you didnt know Dpad stands for directional pad so all you managed to do was give some bad advice no offenseZitat:
Zitat von FaT3oYCG
Thanks. For the fastest with anwser me. What abotu that one.
I'll want to creat a drum app. I wnt to load my sound and associate them to a name. Then I want to, if i push X, per exemple, play the sound associate to "kick" bu tonly once. Do u know how i have to do that.
I alerdy try but i wasn'n able.
If you can't figure that out, stop attempting to create anything. Besides, drum and soundboard apps have already been beaten to death.
look I am all against people putting don new programers for trying, but I might have to kinda agree with TurtlesPwn. I mean there are already a TON of drum and sound apps, so I mean unless you are like dead-set on making this, I would sugest making something else. But thats just me.
The point I was trying to make was that what you were doing was the same in concept as what the previous coder was doing. Your if conditional logic was slightly different, but nothing revolutionary. Your statement of his way being "horrible" got under my skin, since your method displayed nothing novel. Plus it was late and I was cranky.Zitat:
Zitat von TurtlesPwn
Alright, I have a question, hehe, How would I go about unbliting an object. Let me explain, I want like a coin on the screen right, so the character can collect it. I can do that part. But I want to have it disapear when the character walks over the coin. Also how can you put the coins randomly in a selected space like in only in a 100x100 invisible box?? thanx aton
-PSProgramer
My method was made to accomplish the same thing as his method, but he was using if pad:cross() and oldpad:cross() ~= pad:cross() then, which makes three function calls to the input data while only really needing two.Zitat:
Zitat von KleptoOne
PSProgrammer - make a table with the items x, y, image, and a variable indicating whether it has been picked up. when it has not been picked up, blit it and check if the player is over it. then when it is picked up, stop blitting it and stop checking if the player is over it.