Advertising (This ad goes away for registered users. You can Login or Register)

Problems with LUA...

Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
Locked
Leon2342
Posts: 80
Joined: Sun Dec 23, 2012 7:31 pm
Location: Illinois
Contact:

Problems with LUA...

Post by Leon2342 »

I cannotfor the life of me get this **** working...I need to have a menu system where each scene can have at the minimum 1 option that the user can select to switch to another scene, I got the menu all made but as soon as i go into the game, and hit x, nothing happens and it doesnt switch to the next scene, meaning it either is instantly switching back to the first scene or x isn't being detected, so I fixed that but whenever I press x now, the game spazzes out flashing between the two scenes I have for a few seconds before stopping on one of them, so I went back and cahnged things and now it starts with a black screen and after I press x it just flashes between the two scenes, what exactly am I doing wrong?

Here is the code I have

white = Color.new(255,255,255)
grey = Color.new(120,120,120)
black = Color.new(0,0,0)
foyer = Image.load("foyer.jpg")
frontyard = Image.load("frontyard.jpg")
oldpad = Controls.read()
gamestate = "front"
selector = { image = Image.createEmpty(145,15), x = 5,y = 180 }
selector.image:clear(grey)
function sceneFront()
screen:clear()
gamestate = "front"
pad = Controls.read()
screen:blit(0,0,frontyard)
screen:blit(selector.x,selector.y,selector.image)
screen:print(10,183,"Foyer",white)
end
function sceneFoyer()
screen:clear()
gamestate = "foyer"
pad = Controls.read()
screen:blit(0,0,foyer)
screen:blit(selector.x,selector.y,selector.image)
screen:print(10,183,"Front Yard",white)
end
while true do
pad = Controls.read()
if pad:cross() and oldpad:cross() ~= pad:cross() and gamestate == "foyer" then
sceneFront()
else if pad:cross() and oldpad:cross() ~= pad:cross() and gamestate == "front" then
sceneFoyer()
end
screen.flip()
oldpad = pad
end
end
Advertising
OG Vita 3.60 Emulation Machine
PS Vita-PCH2000 stock or something i think lol
Back in my day, I had to teleport to and from school in the snow, uphill, both dimensions!
qwikrazor87
Guru
Posts: 2874
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: Problems with LUA...

Post by qwikrazor87 »

hmm, Lua usually treats variables globally, unless you declare them with local.
You're updating "pad" in all the functions, try changing the name of them in each function and see if the problem still occurs.
Advertising
PSP 2001 - TA-085 - 6.61 PRO-C2
PS Vita 3G - PCH-1101 - 3.65 HENkaku Ensō
Alcatel phone - Android 8.1.0
Laptop - Toshiba Satellite L305D-S5974 - Ubuntu 16.04 LTS
Leon2342
Posts: 80
Joined: Sun Dec 23, 2012 7:31 pm
Location: Illinois
Contact:

Re: Problems with LUA...

Post by Leon2342 »

qwikrazor87 wrote:hmm, Lua usually treats variables globally, unless you declare them with local.
You're updating "pad" in all the functions, try changing the name of them in each function and see if the problem still occurs.
not usre exactly what it is i did differently but i fixed it, code is now as follows

white = Color.new(255,255,255)
foyer = Image.load("foyer.jpg")
frontyard = Image.load("frontyard.jpg")
gamestate = "front"
function sceneFront()
screen:clear()
screen:blit(0,0,frontyard)
screen:print(5,180,"Go to Foyer",white)
end
function sceneFoyer()
screen:clear()
screen:blit(0,0,foyer)
screen:print(5,180,"Go to Front",white)
end

while true do
pad = Controls.read()
if gamestate == "front" then
sceneFront()
end
if gamestate == "foyer" then
sceneFoyer()
end
if pad:cross() and oldpad:cross() ~= pad:cross() and gamestate == "front" then
gamestate = "foyer"
elseif pad:cross() and oldpad:cross() ~= pad:cross() and gamestate == "foyer" then
gamestate = "front"
end
screen.flip()
oldpad = pad
end
OG Vita 3.60 Emulation Machine
PS Vita-PCH2000 stock or something i think lol
Back in my day, I had to teleport to and from school in the snow, uphill, both dimensions!
qwikrazor87
Guru
Posts: 2874
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: Problems with LUA...

Post by qwikrazor87 »

Yeah, I guess it was the issue I mentioned, you removed the pad update from the other functions.
PSP 2001 - TA-085 - 6.61 PRO-C2
PS Vita 3G - PCH-1101 - 3.65 HENkaku Ensō
Alcatel phone - Android 8.1.0
Laptop - Toshiba Satellite L305D-S5974 - Ubuntu 16.04 LTS
Leon2342
Posts: 80
Joined: Sun Dec 23, 2012 7:31 pm
Location: Illinois
Contact:

Re: Problems with LUA...

Post by Leon2342 »

qwikrazor87 wrote:Yeah, I guess it was the issue I mentioned, you removed the pad update from the other functions.
cool, so if i run into anymore issues with things is it alright to contact you directly through a message? I'm just working on a side project to see how much I am able to do with the thing I have set in my mind
OG Vita 3.60 Emulation Machine
PS Vita-PCH2000 stock or something i think lol
Back in my day, I had to teleport to and from school in the snow, uphill, both dimensions!
noname120
Developer
Posts: 777
Joined: Thu Oct 07, 2010 4:29 pm

Re: Problems with LUA...

Post by noname120 »

You should indent your code, otherwise it will quickly become very hard to read.
Funny stuff
<yifanlu> I enjoy being loud and obnoxious
<yifanlu> rooting an android is like getting a hooker pregnant
<xerpi> I sometimes think I should leave all this stressing **** and be a farmer instead
Rinnegatamante
VIP
Posts: 912
Joined: Sat Mar 26, 2011 10:02 am
Contact:

Re: Problems with LUA...

Post by Rinnegatamante »

Try changing this: oldpad:cross() ~= pad:cross() with this: not oldpad:cross()
If you want, visit my website: http://rinnegatamante.it :D
Locked

Return to “Programming and Security”