lol, you need dev status. Funny thing is mine said "Neophyte" (even though i think it still should for now).Zitat:
Zitat von emericaska8r
Also, about that, i am pming a moderator or administrator about that to get it removed...
Printable View
lol, you need dev status. Funny thing is mine said "Neophyte" (even though i think it still should for now).Zitat:
Zitat von emericaska8r
Also, about that, i am pming a moderator or administrator about that to get it removed...
oh, yea and like i just deposited all my points to the bank, and now it says i don't have enough points to enter the bank anymore. thats so gay
Yea, You need to have 50 to enter it.
Ahem.......Sorry it was my fault to start this off topic; this is a lua help thread. Lol....
i fixed my other error and now am wondering a question i defined player width and player height like this:
but in the collision function i need to use player width also how do i call the variables if they look like the above code? or do i need to assign new varibales and assign them the dimensions of the image?Code:player:width()
player:height()
--edit--
also i calls other variables such as (variable name).width how do I need to assign those as well?
Zitat:
Zitat von %chrono trigger%
you could do this:
Code:if (player.x + player:width() > whatever) etc.
but, its more efficient to do this:
Code:pW = player:width()
--in your collision function--
if (player.x + pW > whatever) etc.
that way, the psp doesnt spend time each frame checking the width of the player over and over again.
--edit--
ok im moving rather smoothly now except when i added this to my code:
it gives me an error saying attemtp to call method 'height' (a nil value)Code:Jewel = {}
Jewel[1] = {x=350,y=150,height = Jewel:height(), width = Jewel:width() }
Jewel[2] = {x=150,y=100,height = Jewel:height(), width = Jewel:width() }
Jewel[3] = {x=200,y=250,height = Jewel:height(), width = Jewel:width() }
Jewel[4] = {x=300,y=120,height = Jewel:height(), width = Jewel:width() }
Jewel[5] = {x=100,y=225,height = Jewel:height(), width = Jewel:width() }
Well, seems to me like you don't have a 'Jewel' image created. Whether it be loaded via Image.load as an example, or created, via Image.createEmpty(n,n).
does anyone know a lua game with scrolling? i have scrolling down, its that in my game i create objects that i want for to STAY on the scrolling background. (example, throw a ...rock or something, it lands and stays, i move character, screen scrolls, rock disappears from screen, go back, rock reappears in the place it was thrown.) i just need to know if someone else has done this so i can get an idea of how to do it myself.
so basically, does anyone know a game with scrolling and has newly created objects scroll with the map too?
You got to have two main axis, x and y.Zitat:
Zitat von EminentJonFrost
For example:
Now you make Screen.x and Screen.y togglable, then you can start to place out your sprites and stuff. Simple enugh?Code:Screen.x = 0
Screen.y = 0
screen:blit(x+Screen.x,y+Screen.y,image) -- You can make this a function so you don't have to write the "+Screen.x" stuff over and over again.
i'm afraid not...whats making this difficult in my case is that, not only does the screen scroll, but the player can move (in a limited box, you can say) around too. so my object appears around my character and it moves how it should on-screen (like if my character goes up, it doesnt). but i want for it to stop, and be part of the background, which scrolls, so now my object must change from player-screen-based coordinates to map coordinates. its complicated...
oh yes, my view is top-down.
Yeah, i guessed your game was in a top-down view. I got a unfinnished game with sidescrolling, not top-down view, but it's nearly the same. I think you might want to have a look at it.Zitat:
Zitat von EminentJonFrost
MSN: [email protected]
um, ok sure!
edit - i added you. sorry for the delayed response, my internet acted wierd....
well this collision is really throwing me off. Can i create a empty image and then paste a .png file on it?
that wouldnt do anything different. theres no point (that i know of) to blitting an image, in an image, when all you want is...the first image. post some code up, i'll see if i can be of assistance! :)Zitat:
Zitat von %chrono trigger%
jeres the first half of my code:
Code:red = Color.new(255,0,0)
background = Image.load("b.png")
player = Image.load("a.png")
jewel = Image.load("c.png")
playerWidth = 50
playerHeight = 50
screenwidth = 480 - player:width()
screenheight = 272 - player:width()
Player = {}
Player[1] = {x=10,y=10}
Background = {}
Background[1] = {x=0,y=0}
Jewel = {}
Jewel[1] = {x=350,y=150, height = jewel:height(), width = jewel:width() }
Jewel[2] = {x=150,y=100, height = jewel:height(), width = jewel:width() }
Jewel[3] = {x=200,y=250, height = jewel:height(), width = jewel:width() }
Jewel[4] = {x=300,y=120, height = jewel:height(), width = jewel:width() }
Jewel[5] = {x=100,y=225, height = jewel:height(), width = jewel:width() }
Jewel:height()
Jewel:width()
function collisionCheck(Jewel)
if (Player[1].x + playerWidth > Jewel[1].x) and (Player[1].x < Jewel[1].x + Jewel[1].width) and (Player[1].y + playerHeight > Jewel[1].y) and (Player[1].y < Jewel[1].y + Jewel[1].height) then
Player.x = oldx
Player.y = oldy
end
end
function collisionCheck(Jewel)
if (Player[1].x + playerWidth > Jewel[2].x) and (Player[1].x < Jewel[2].x + Jewel[2].width) and (Player[1].y + playerHeight > Jewel[2].y) and (Player[1].y < Jewel[2].y + Jewel[2].height) then
Player.x = oldx
Player.y = oldy
end
end
function collisionCheck(Jewel)
if (Player[1].x + playerWidth > Jewel[3].x) and (Player[1].x < Jewel[3].x + Jewel[3].width) and (Player[1].y + playerHeight > Jewel[3].y) and (Player[1].y < Jewel[3].y + Jewel[3].height) then
Player.x = oldx
Player.y = oldy
end
end
function collisionCheck(Jewel)
if (Player[1].x + playerWidth > Jewel[4].x) and (Player[1].x < Jewel[4].x + Jewel[4].width) and (Player[1].y + playerHeight > Jewel[4].y) and (Player[1].y < Jewel[4].y + Jewel[4].height) then
Player.x = oldx
Player.y = oldy
end
end
function collisionCheck(Jewel)
if (Player[1].x + playerWidth > Jewel[5].x) and (Player[1].x < Jewel[5].x + Jewel[5].width) and (Player[1].y + playerHeight > Jewel[5].y) and (Player[1].y < Jewel[5].y + Jewel[5].height) then
Player.x = oldx
Player.y = oldy
end
end
you put player:width twice..Code:screenwidth = 480 - player:width() --did you MEAN to do this?
screenheight = 272 - player:width()
also, it could be confusing to have an image and an array both called 'player'. i know one is capitalized, and that it should work fine, but it could lead to problems later.
i shortened this:
in place of this:Code:Jewel = {}
for a = 1, 5 do
Jewel[a] = {x=350,y=150, height = jewel:height(), width = jewel:width() }
end
Code:Jewel = {}
Jewel[1] = {x=350,y=150, height = jewel:height(), width = jewel:width() }
Jewel[2] = {x=150,y=100, height = jewel:height(), width = jewel:width() }
Jewel[3] = {x=200,y=250, height = jewel:height(), width = jewel:width() }
Jewel[4] = {x=300,y=120, height = jewel:height(), width = jewel:width() }
Jewel[5] = {x=100,y=225, height = jewel:height(), width = jewel:width() }
yes i did thats not the problem and disregard Jewel:height() and the width one they shouldnt be there
HERES the problem:Zitat:
Zitat von %chrono trigger%
remember how i shortened the part before? you announced the SAME function 5 times, so it only affected 1 jewel, since you kept changing which jewel number each time you defined it.Code:function collisionCheck(Jewel)
if (Player[1].x + playerWidth > Jewel[1].x) and (Player[1].x < Jewel[1].x + Jewel[1].width) and (Player[1].y + playerHeight > Jewel[1].y) and (Player[1].y < Jewel[1].y + Jewel[1].height) then
Player.x = oldx
Player.y = oldy
end
end
try this:
Code:function collisionCheck(Jewel)
for a = 1, 5 do
if (Player[a].x + playerWidth > Jewel[a].x) and (Player[a].x < Jewel[a].x + Jewel[a].width) and (Player[a].y + playerHeight > Jewel[a].y) and (Player[a].y < Jewel[a].y + Jewel[a].height) then
Player.x = oldx
Player.y = oldy
end
end
end
ok I wasnt sure if i should post this in this thread or not but here it is:
For school im doing a long term project on developing a program for the psp in c/c++.
I thought i had longer than i had so i cant learn the amount of info i need in time.
Basically is there a way that i can imbed a lua file in an eboot so that even if you open up the eboot you couldnt tell that its a lua file or w/e inside. This way i could just pretend its in c and i could make it better and get a better grade since im pretty good at lua
i dont think so...but i dont know about eboots, so you'll want a second opinion.Zitat:
Zitat von jamz1825
therers my new optimized code so i dont have to many if statements but it gives me the error attempt to index field '?' (a nil value)Code:function collisionCheck(Jewel)
local i = 1
while i <=5 do
if (Player[1].x + playerWidth > Jewel[i].x) and (Player[1].x < Jewel[i].x + Jewel[i].width) and (Player[1].y + playerHeight > Jewel[i].y) and (Player[1].y < Jewel[i].y + Jewel[i].height) then
Player.x = oldx
Player.y = oldy
end
i = i +1
end
end
change every '1' in a these: [ ] to an 'i'. and it should work.Zitat:
Zitat von %chrono trigger%
also, put this: for i = 1, 5 do
instead of: while i <=5 do
it cycles the code with 'i' changing its values, therefore, affecting 5 jewels. it basically works the same, but you can code how you want. :)
like that?Zitat:
Zitat von %chrono trigger%
-edit-
i guess i did something wrong as i am getting another error
like this:
:)Code:function collisionCheck(Jewel)
for i = 1, 5 do
if (Player[i].x + playerWidth > Jewel[i].x) and (Player[i].x < Jewel[i].x + Jewel[i].width) and (Player[i].y + playerHeight > Jewel[i].y) and (Player[i].y < Jewel[i].y + Jewel[i].height) then
Player.x = oldx
Player.y = oldy
end
end
end
what does the:
do?Code:local i = 1
Zitat:
Zitat von emericaska8r
'local' means that only the function you called it in can access the variable. for example, if i did this:
Code:function BOB()
local joe = 0
end
while true do
joe = joe + 1
end
that would result in an error. but this:
that would work perfectly.Code:function BOB()
local joe = 0
joe = joe + 1
end
while true do
BOB()
end
got a problem ( a stupid one at that), for some reason, in my 2d side scroller, when my charactor moves right and hits the midde of the screen, the background scrolls AND my character still moves forward, yet, when he goes left it works Perfectly, i dont understand, it was working good before, but I must have been stupid and put something in the code to make it stop working, i copied the left movement code to the right and configured it to the right animation but still no good, here is my movement code,
Spoiler for code:
the 2 blocks of code in front are for when the player reaches the middle of the screen, he is "supposedly" stops going forward 4 pixels and the background starts to scroll, (supposedly cuz this doesn't happen for when you press right) the other two code is for when he reaches the end of the screens, it stops scrolling and he starts to walk normally and make sures to stop when he reaches the end of the screen. Help for this would be great, if you need the full code + resources then PM me, I am absilutly sure this is a really simple problem that i just cant find.
thanks in advance, Later!
-Jaws-:tup:
Im too busy to look into that deeply, but give this try for your FIRST to if's there...
Code:if pad:right() and santaX >= 200 and bg4.x > 0 then
scroll = "true"
santaState = "runningR"
santaDirection = "right"
santaX = 200
bg1.x = bg1.x - 3
bg2.x = bg2.x - 3
bg3.x = bg3.x - 3
bg4.x = bg4.x - 3
else
scroll = "false"
end
if pad:left() and santaX <= 155 and bg1.x < 0 then
scroll = "true"
santaState = "runningL"
santaDirection = "left"
santaX = 155
bg1.x = bg1.x + 3
bg2.x = bg2.x + 3
bg3.x = bg3.x + 3
bg4.x = bg4.x + 3
else
scroll = "false"
end
Ahhh yup, that did , thanks again! (another reason to credit you:) )
thanks man
y i didn't think to simply state santa's X value is beyond me...
thanks again :)
Simple logic ;)
thanks manZitat:
Zitat von Grimfate126
Well if your professor or whatever has seen anything on psp he may easily be able to spot it. But if he doesn't own a psp then he will not know whatsoever. But for a project like that you will most likely have to show him your sources so...Zitat:
Zitat von jamz1825
I'm trying to learn to learn how to use functions in lua, but I get a bunch of errors when i try to transfer the value of a variable from a function back to a variable of the same name in the main loop.
sigh, I'm probably just not getting something. Does anyone know where I can learn how to use functions correctly? All of the newby tutorials I've come across have been too basic or un-indepth for what i am trying to do.
www.evilmana.com
And heres something Im just gonna throw together that should work
You mean stuff like that doesnt work for you? If not then your probally doing something wrong check the tuts on evilmana for more info.Code:function addition()
variable = 2
bill = 3
check = variable + bill
end
while true do
addition()
screen:print(0,0,check,red)
screen.waitVblankStart()
screen.flip
end
what if he ask's to see the source?Zitat:
Zitat von jamz1825
wait wait, lemme get this straight. you used the same .. word for a variable and a function?Zitat:
Zitat von joshparrisjosh
like this?:
if so, that wouldnt work, as you just found out.Code:variable = something
(some code)
function variable()
if this has nothing to do with your problem, well then, the first thing you gotta know about getting help is that you post your code up and say what error luaplayer gives you. that way, people can .. well help you. :)
Okay well here's my code, just promise not to make fun of me because of how bad it seems. :o
Zitat:
white = Color.new(255,255,255)
green = Color.new(0,255,0)
locke = 1
truewords = nil
function loopy(locke, truewords)
while locke > 0 do
screen:clear()
pad = Controls.read()
screen:print(0,0,"Pick a song", white)
if pad:up() then
screen:print(100,100,"tur n it up",green)
if pad:up() and pad:cross() then
locke = 0
truewords = "turn it up"
end
end
if pad:down() then
screen:print(100,100,"the sharpest lives", green)
if pad:down() and pad:cross() then
locke = 0
truewords = "the sharpest lives"
end
end
screen.waitVblankStart()
screen.flip()
end
return truewords
return locke
end
while true do
screen:clear()
pad = Controls.read()
loopy(locke, truewords)
if locke > -1 then
screen:print(100,100,"pre ss x to continue")
if pad:cross() then
locke = locke - 1
end
end
if locke == -1 then
screen:print(100,100,true words,white)
end
screen.waitVblankStart()
screen.flip()
end
First off dont quote your code. Code your code . It stops the smileys and the space problem. Secondly whats the problem with your code?
EDIT: O AND [email protected]!!!!!!!!!!!!!!!! SWEEEEEEEEEEEETTTTTTTTTTT TTTTTTTTTT YAAAAAAAAAAA
400 pOSTS !!! YA
the problem with my code is that without the "function loopy()" everything is gravy, but in its current state as posted... after the code executes to the point where it should blit the varible "truewords" it get the error that truewords is a nil value. This to me seems to point in the dirrection that my "function loopy()" isn't changing the value of truewords into a string as i would like it to.
Is this possible? I mean to change it to string through the use of a function?