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

[LUA] Need help with code plz

Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 » Wed Dec 26, 2012 4:18 am

qwikrazor87 wrote:Hmm... I don't see what's wrong. :?
Well, happy x-mas, and since I actually got the writing to show up in this code I need help finalizing it.

In this part the player will cross the other one and a split second later the writing will disappear, so what I ask is how do you keep the text of whose it on screen but print only who is it on screen because when the players cross it prints "player2 is it" and "player1 is it" on the screen at the same time.

Code: Select all

if player1x == player2x and player1y == player2y then
screen:print(20, 20, "player2 is it",white)
end
if player2x == player1x and player2y == player1y then
screen:print(20, 20, "player1 is it",white)
end
The whole code\/

Code: Select all

--Created by dragonxtamer596
black = Color.new(0,0,0)
white = Color.new(255,255,255)

Room_width = 480
Room_height = 272
player1x =240
player1y =136
player2x =120
player2y =80

background=Image.load("images/Background.PNG")
player1=Image.load("images/Player1.PNG")
player2=Image.load("images/Player2.PNG")

function checkcontrols()
pad = Controls.read()
if pad:start() then
screen:fillRect(0, 0, 480, 272, black)
dofile("index.lua")
end

if pad:right() then
player1x = player1x +2
end

if pad:left() then
player1x = player1x -2
end

if pad:up() then
player1y = player1y -2
end

if pad:down() then
player1y = player1y +2
end

if pad:circle() then
player2x = player2x +2
end

if pad:square() then
player2x = player2x -2
end

if pad:triangle() then
player2y = player2y -2
end

if pad:cross() then
player2y = player2y +2
end
end

function drawall() 
screen:blit(0,0,background)
screen:blit(player1x,player1y,player1)
screen:blit(player2x,player2y,player2)
if player1x == player2x and player1y == player2y then
screen:print(20, 20, "player2 is it",white)
end
if player2x == player1x and player2y == player1y then
screen:print(20, 20, "player1 is it",white)
end
screen.waitVblankStart()
screen.flip()
end 

while true do 
checkcontrols()
drawall()
end
Advertising

User avatar
qwikrazor87
Guru
Posts: 2839
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA] Need help with code plz

Post by qwikrazor87 » Wed Dec 26, 2012 5:09 am

Merry christmas. :D
You need a value to determine who is it or not.
Maybe do something like,

Code: Select all

whoisit = math.floor(math.random(1, 3))
istag = "no"

while true do
screen:clear()
screen:print(20, 20, "player"..whoisit.." is it",white)
  if player1x == player2x and player1y == player2y then
    if istag == "no" then
    istag = "yes"
    whoisit = whoisit + 1
      if whoisit > 2 then
      whoisit = 1
      end
    end
  else
    if istag == "yes" then
    is tag = "no"
    end
  end
screen.waitVblankStart()
screen.flip()
end
I haven't tested it out, but it should work.
Advertising
PSP N1000 - TA-091 - 5.70 QHEN
PSP 2001 - TA-085 v1 - 6.60 PRO-C
PSP 1001 - TA-086 - 6.60 PRO-C
PS Vita 3G - PCH-1101 - 3.60 taiHEN
Laptop HP Pavilion g7 - Ubuntu 12.04 LTS

dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 » Wed Dec 26, 2012 6:45 pm

qwikrazor87 wrote:Merry christmas. :D
You need a value to determine who is it or not.
Maybe do something like,

Code: Select all

whoisit = math.floor(math.random(1, 3))
istag = "no"

while true do
screen:clear()
screen:print(20, 20, "player"..whoisit.." is it",white)
  if player1x == player2x and player1y == player2y then
    if istag == "no" then
    istag = "yes"
    whoisit = whoisit + 1
      if whoisit > 2 then
      whoisit = 1
      end
    end
  else
    if istag == "yes" then
   [u] is tag = "no"[/u]
    end
  end
screen.waitVblankStart()
screen.flip()
end
I haven't tested it out, but it should work.
It works....IT WORKS tears of joy. :cry: The only issue with it was the is wasn't next to the tag now I just need to add collision, smaller characters, and a bigger room. :D

User avatar
qwikrazor87
Guru
Posts: 2839
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA] Need help with code plz

Post by qwikrazor87 » Wed Dec 26, 2012 8:08 pm

:D
Well if you want to add the detection of collision for their edges just change the parameters to this.

Code: Select all

whoisit = math.floor(math.random(1, 3))
istag = "no"

while true do
screen:clear()
screen:print(20, 20, "player"..whoisit.." is it",white)
  if player1x <= player2x + player2:width() and player1y <= player2y + player2:height() and player1x >= player2x and player1y >= player2y then
    if istag == "no" then
    istag = "yes"
    whoisit = whoisit + 1
      if whoisit > 2 then
      whoisit = 1
      end
    end
  else
    if istag == "yes" then
   [u] is tag = "no"[/u]
    end
  end
screen.waitVblankStart()
screen.flip()
end
If there is something wrong with it let me know, but I'm sure it'll work.
PSP N1000 - TA-091 - 5.70 QHEN
PSP 2001 - TA-085 v1 - 6.60 PRO-C
PSP 1001 - TA-086 - 6.60 PRO-C
PS Vita 3G - PCH-1101 - 3.60 taiHEN
Laptop HP Pavilion g7 - Ubuntu 12.04 LTS

dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 » Thu Dec 27, 2012 3:19 am

I have questions about the lua players you suggested to me earlier.
PGE and LuaDevR0 >\/
For LuaDevR0 does your lua code have to be in Spanish?
And a question for both do I have to change my code to make them work on either?

User avatar
qwikrazor87
Guru
Posts: 2839
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA] Need help with code plz

Post by qwikrazor87 » Thu Dec 27, 2012 3:35 am

For LuaDevR0 does your lua code have to be in Spanish?
No, you can code in whatever language you want.
And a question for both do I have to change my code to make them work on either?
There are some function names you will have to change, for example,
Lua Player 0.20

Code: Select all

picture = Image.load(pathtoimage)

list = System.listDirectory(directory)
LuaDEV R0

Code: Select all

picture = image.load(pathtoimage)

list = files.list(directory)
pgelua

Code: Select all

picture = pge.texture.load(pathtoimage)

dir = pge.dir.open(directory)
list = dir:read()
dir:close()
Those are just a few of the differences, but as you can see with pgelua you have to work a little more to get things done, that is why I suggest LuaDEV over pgelua.
It may be a little confusing at first but it's worth it. LuaDEV and pgelua are much faster.
PSP N1000 - TA-091 - 5.70 QHEN
PSP 2001 - TA-085 v1 - 6.60 PRO-C
PSP 1001 - TA-086 - 6.60 PRO-C
PS Vita 3G - PCH-1101 - 3.60 taiHEN
Laptop HP Pavilion g7 - Ubuntu 12.04 LTS

dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 » Thu Dec 27, 2012 3:55 am

What's the diffence between LME and ME cfw? viewtopic.php?f=17&t=7334
I read this...
-I want to try 6.60ME can i return back to other firmwares?
There is a downgrader, some1 released the 6.60 version
...and I'm wondering does that mean I can't or can go back to my Pro-B if I don't like it?
Also which ones more like pro cfw because Pro is super easy to navigate press cross to start cross again to launch/finalize?

User avatar
qwikrazor87
Guru
Posts: 2839
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA] Need help with code plz

Post by qwikrazor87 » Thu Dec 27, 2012 4:05 am

They both install and launch the same way, and can both be uninstalled.
With ME/LME you can run 1.50 homebrew with the leda plugin.
With PRO you can play adhoc games online with the PRO online client.
They both have there pros and cons.
PSP N1000 - TA-091 - 5.70 QHEN
PSP 2001 - TA-085 v1 - 6.60 PRO-C
PSP 1001 - TA-086 - 6.60 PRO-C
PS Vita 3G - PCH-1101 - 3.60 taiHEN
Laptop HP Pavilion g7 - Ubuntu 12.04 LTS

dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA] Need help with code plz

Post by dragonxtamer596 » Sun Jan 13, 2013 9:21 pm

Can you help with changing my code to lua devR0?

Code: Select all

blue = Color.new(0, 50, 175)
white = Color.new(255,255,255)
black = Color.new(0,0,0)

ms = 1
mms = 4

oldpad = Controls.read()

while true do
screen:clear()
pad = Controls.read()

if pad:up() and oldpad:up() ~= pad:up() then
ms = ms - 1
end
if pad:down() and oldpad:down() ~= pad:down() then
ms = ms + 1
end
if ms > mms then
ms = 1
elseif ms <= 0 then
ms = mms
end

mc = { white,white,white,white }
mc[ms] = blue
screen:print(98,107,"Game",mc[1])
screen:print(98,117,"Option 2",mc[2])
screen:print(98,127,"Option 3",mc[3])
screen:print(98,137,"Option 4",mc[4])

if pad:cross() and not oldpad:cross() and ms == 1 then
screen:fillRect(0, 0, 480, 272, black)
dofile("Game.lua")
end

if pad:cross() and not oldpad:cross() and ms == 2 then
end

if pad:cross() and not oldpad:cross() and ms == 3 then
end

if pad:cross() and not oldpad:cross() and ms == 4 then
end

if ms <= 0 then
ms = 4
end

if ms >= 5 then
ms = 1
end

screen.waitVblankStart()
screen.flip()
oldpad = pad
end

Code: Select all

--Created by dragonxtamer596
black = Color.new(0,0,0)
white = Color.new(255,255,255)

whoisit = math.floor(math.random(1, 3))
istag = "no"

Room_width = 480
Room_height = 272
player1x =240
player1y =136
player2x =120
player2y =80

background=Image.load("images/Background.PNG")
player1=Image.load("images/Player1.PNG")
player2=Image.load("images/Player2.PNG")

function checkcontrols()
pad = Controls.read()
if pad:start() then
screen:fillRect(0, 0, 480, 272, black)
dofile("script.lua")
end

if pad:right() then
player1x = player1x +2
end

if pad:left() then
player1x = player1x -2
end

if pad:up() then
player1y = player1y -2
end

if pad:down() then
player1y = player1y +2
end

if pad:circle() then
player2x = player2x +2
end

if pad:square() then
player2x = player2x -2
end

if pad:triangle() then
player2y = player2y -2
end

if pad:cross() then
player2y = player2y +2
end
end

function drawall() 
screen:clear()
screen:blit(0,0,background)
screen:blit(player1x,player1y,player1)
screen:blit(player2x,player2y,player2)
screen:print(20, 20, "player"..whoisit.." is it",white)
  if player1x <= player2x + player2:width() and player1y <= player2y + player2:height() and player1x >= player2x and player1y >= player2y then
    if istag == "no" then
    istag = "yes"
    whoisit = whoisit + 1
      if whoisit > 2 then
      whoisit = 1
      end
    end
  else
    if istag == "yes" then
    istag = "no"
    end
  end
screen.waitVblankStart()
screen.flip()
end 

while true do 
checkcontrols()
drawall()
end
Does Lua dev play music?
what type if so?
What file is the file lua dev first reads? example Index.lua, Script.lua...
Also could this be pulled off....

Code: Select all

black = Color.new(0,0,0)

image1=Image.load("images/image1.PNG")
screen:blit(0,0,image1)

if image1=Image.load("images/image1.PNG") and not image1=Image.load("images/image1.PNG") then
screen:fillRect(0, 0, 480, 272, black)
screen:clear()
image2=Image.load("images/image2.PNG")
screen:blit(0,0,image2)
end

if image1=Image.load("images/image2.PNG") and not image1=Image.load("images/image2.PNG") then
screen:fillRect(0, 0, 480, 272, black)
screen:clear()
image3=Image.load("images/image3.PNG")
screen:blit(0,0,image3)
end

while true do
screen.waitVblankStart()
screen.flip()
end

User avatar
qwikrazor87
Guru
Posts: 2839
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA] Need help with code plz

Post by qwikrazor87 » Mon Jan 14, 2013 12:32 am

Code: Select all

blue = color.new(0,0,255)
white = color.new(255,255,255)
black = color.new(0,0,0)

ms = 1
mms = 4

while true do
screen.clear()
controls.read()

  if controls.press("up") then
  ms = ms - 1
  end
  if controls.press("down") then
  ms = ms + 1
  end
  if ms > mms then
  ms = 1
  elseif ms <= 0 then
  ms = mms
  end

mc = {white, white, white, white}
mc[ms] = blue
screen.print(98, 107, "Game", mc[1])
screen.print(98, 117, "Option 2", mc[2])
screen.print(98, 127, "Option 3", mc[3])
screen.print(98, 137, "Option 4", mc[4])

  if controls.press("cross") and ms == 1 then
  draw.fillrect(0, 0, 480, 272, black)
  dofile("Game.lua")
  end
  if controls.press("cross") and ms == 2 then
  end
  if controls.press("cross") and ms == 3 then
  end
  if controls.press("cross") and ms == 4 then
  end
  if ms <= 0 then
  ms = 4
  end
  if ms >= 5 then
  ms = 1
  end
screen.waitvblankstart()
screen.flip()
end

Code: Select all

black = color.new(0, 0, 0)
white = color.new(255, 255, 255)

whoisit = math.floor(math.random(1, 3))
istag = "no"

Room_width = 480
Room_height = 272
player1x = 240
player1y = 136
player2x = 120
player2y = 80

background = image.load("images/Background.PNG")
player1 = image.load("images/Player1.PNG")
player2 = image.load("images/Player2.PNG")

function checkcontrols()
controls.read()
  if controls.press("start") then
  draw.fillrect(0, 0, 480, 272, black)
  dofile("script.lua")
  end

  if controls.right() then
  player1x = player1x + 2
  end

  if controls.left() then
  player1x = player1x - 2
  end

  if controls.up() then
  player1y = player1y - 2
  end

  if controls.down() then
  player1y = player1y + 2
  end

  if controls.circle() then
  player2x = player2x + 2
  end

  if controls.square() then
  player2x = player2x - 2
  end

  if controls.triangle() then
  player2y = player2y - 2
  end

  if controls.cross() then
  player2y = player2y + 2
  end
end

function drawall() 
screen.clear()
background:blit(0,0)
player1:blit(player1x, player1y)
player2:blit(player2x, player2y)
screen.print(20, 20, "player"..whoisit.." is it", white)
  if player1x <= player2x + player2:width() and player1y <= player2y + player2:height() and player1x >= player2x and player1y >= player2y then
    if istag == "no" then
    istag = "yes"
    whoisit = whoisit + 1
      if whoisit > 2 then
      whoisit = 1
      end
    end
  else
    if istag == "yes" then
    istag = "no"
    end
  end
screen.waitvblankstart()
screen.flip()
end

while true do 
checkcontrols()
drawall()
end
dragonxtamer596 wrote:Does Lua dev play music?
what type if so?
Yes, mp3, wav, at3 and bgm.
dragonxtamer596 wrote:What file is the file lua dev first reads? example Index.lua, Script.lua...
It looks for two files, script.lue if the file is encrypted, or script.lua if it's not encrypted.
dragonxtamer596 wrote:Also could this be pulled off....

Code: Select all

black = Color.new(0,0,0)

image1=Image.load("images/image1.PNG")
screen:blit(0,0,image1)

if image1=Image.load("images/image1.PNG") and not image1=Image.load("images/image1.PNG") then
screen:fillRect(0, 0, 480, 272, black)
screen:clear()
image2=Image.load("images/image2.PNG")
screen:blit(0,0,image2)
end

if image1=Image.load("images/image2.PNG") and not image1=Image.load("images/image2.PNG") then
screen:fillRect(0, 0, 480, 272, black)
screen:clear()
image3=Image.load("images/image3.PNG")
screen:blit(0,0,image3)
end

while true do
screen.waitVblankStart()
screen.flip()
end
The way you made the statements are wrong.
It should be like this when asking if an image is loaded.

Code: Select all

image1=image.load("images/image1.PNG")
  if image1 then
  --code here
  end
In your code you are asking if the image is loaded and if it's not loaded at the same time,

Code: Select all

if image1 and not image1 then
--code here
end
That will not bring out the results you are expecting.
PSP N1000 - TA-091 - 5.70 QHEN
PSP 2001 - TA-085 v1 - 6.60 PRO-C
PSP 1001 - TA-086 - 6.60 PRO-C
PS Vita 3G - PCH-1101 - 3.60 taiHEN
Laptop HP Pavilion g7 - Ubuntu 12.04 LTS

Post Reply

Return to “Programming and Security”