thanks d00dZitat:
Zitat von dragaron
Printable View
thanks d00dZitat:
Zitat von dragaron
and you have to addZitat:
Zitat von montrob
math.randomseed(os.time() )
at the beginning, outside the loop
have you guys just gone right pass my question??
ok how do i start the randomization?
math.randomseed(os.time() ) makes it so the numbers are TRULY random based on the time. If you didnt do this, every time you started luaplayer, the 'random' numbers generated would be the same. You call this at the begining of your program.
math.random(low,high) returns an integer between low and high. It's that simple.
or you can just define the high one and lua well auto set low to 1
my code:
Code:pad = Controls.read()
dx = pad:analogX()
dy = pad:analogY()
if math.abs(dx) > 32 then
cursorx = cursorx + dx / 64
height = height +1
end
if math.abs(dy) > 32 then
cursory = cursory + dy / 64
end
how can i make it so that if the analog stik goes down, height decreases by 1?right now, if you go up or down, the height increases.
Ok, here goes...
I've been coding Lua for over three months now, and somewhere I got stuck. I'm trying to move multiple objects around my screen, using the same function. Something like a rack of balls on a pool table. Here it is:
This function moves the object in a given "angle" for "a" pixels, untill "speed / a" reaches zero.Zitat:
function moving()
a = speed / 500
if a >= 0 then
if ball.x <= 6 or ball.x >= 460 then
angle = pi - angle
end
if ball.y <= 5 or ball.y >= 252 then
angle = angle * (-1)
end
ball.x = ball.x + math.cos(angle) * a
ball.y = ball.y + math.sin(angle) * a
speed = speed - 10
end
screen:blit(ball.x,ball.y ,BallNumber,true)
end
I would like to enter some variables when running the function, like so:
Now comes my problem: if call this function inside my mainloop, it gets repeated over and over, ball.x and ball.y would get resetted every time. How could I get this to work?Zitat:
function moving(speed, angle, ball.x, ball.y, BallNumber)
you have to make a table where there are n balls. Then in that function make a for loop so that it happens for all the balls.
Hey Altair,
could you give me an example of how that table would look like?