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

[LUA]I'm having an issue with a multiplayer game

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

[LUA]I'm having an issue with a multiplayer game

Post by dragonxtamer596 »

I connect to a wireless internet connection. Then everything blits to the screen with no errors. It then freezes and my psp turns off with a popping sound what is the issue?

Code: Select all

green = color.new(0,128,0)
white = color.new(255,255,255)
brown = color.new(156,90,60)
black = color.new(0,0,0)
darkg = color.new(70,70,70)
lightg = color.new(180,180,180)
red = color.new(255,0,0)
blue = color.new(0,0,255)

success = wlan.init()
if success ~= 1 then
   screen.print(200,150,"can't connect")
end

timer = 0

name = "Dragon"

if not text1 then
text1 = 0
end
if not dagger1 then
dagger1 = 1
end
if not axe1 then
axe1 = 0
end
if not broadsword1 then
broadsword1 = 0
end
if not elucidator1 then
elucidator1 = 0
end
if not morningstar1 then
morningstar1 = 0
end
if not spear1 then
spear1 = 0
end
if not scimitar1 then
scimitar1 = 0
end
if not kopesh1 then
kopesh1 = 0
end
if not cloth1 then
cloth1 = 1
end
if not leather1 then
leather1 = 0
end
if not mail1 then
mail1 = 0
end
if not black1 then
black1 = 0
end
if not steel1 then
steel1 = 0
end
if not holy1 then
holy1 = 0
end
if not weapon then
weapon = "dagger"
end
if not armor then
armor = "cloth"
end

if not Level then
Level = 1
end
if not Experience then
Experience = 0
end
if not attributes then
attributes = 0
end
if not nextlevel then
nextlevel = 8
end
if not mhealth then
mhealth = 0
end
if not mmana then
mmana = 0
end
if not damage1 then
damage1 = 0
end
if not defence1 then
defence1 = 0
end
if not spells1 then
spells1 = 0
end

if not myCash then
myCash = 0
end
if not tarea then
tarea = 1
end
if not area then
area = 1
end

if not hpotioncost then
hpotioncost = 50
end
if not mpotioncost then
mpotioncost = 20
end
if not hpotionsell then
hpotionsell = 25
end
if not mpotionsell then
mpotionsell = 10
end

if not axebuy then
axebuy = 1500
end
if not broadswordbuy then
broadswordbuy = 3000
end
if not morningstarbuy then
morningstarbuy = 2250
end
if not spearbuy then
spearbuy = 1250
end
if not scimitarbuy then
scimitarbuy = 2500
end
if not kopeshbuy then
kopeshbuy = 500
end
if not leatherbuy then
leatherbuy = 1000
end
if not mailbuy then
mailbuy = 1500
end
if not blackbuy then
blackbuy = 1800
end
if not steelbuy then
steelbuy = 2550
end
if not holybuy then
holybuy = 6000
end

if not daggersell then
daggersell = 25
end
if not axesell then
axesell = 375
end
if not broadswordsell then
broadswordsell = 750
end
if not morningstarsell then
morningstarsell = 550
end
if not spearsell then
spearsell = 300
end
if not scimitarsell then
scimitarsell = 625
end
if not kopeshsell then
kopeshsell = 125
end
if not clothsell then
clothsell = 125
end
if not leathersell then
leathersell = 250
end
if not mailsell then
mailsell = 375
end
if not blacksell then
blacksell = 450
end
if not steelsell then
steelsell = 625
end
if not holysell then
holysell = 1500
end

if not hpotions then
hpotions = 0
end
if not mpotions then
mpotions = 0
end

if not healthbar then
healthbar = 10
end
if not manabar then
manabar = 10
end

if not hattributes then
hattributes = 0
end
if not mattributes then
mattributes = 0
end
if not health then
health = 100 + mhealth
end
if not mana then
mana = 100 + mmana
end

if not quest then
quest = 0
end

mxhealth = 100 + mhealth

mxmana = 100 + mmana

if not spells2 then
spells2 = 0
end

socket = socket.connect("irc.freenode.net", 6667)

background = image.create(480,272,green)

player = image.create(15,15,white)

block1 = image.create(60,18,brown)

block2 = image.create(480,1,black)

block3 = image.create(1,272,black)

block4 = image.create(133,64,darkg)

block6 = image.create(60,64,darkg)

block5 = image.create(27,7,lightg)

block7 = image.create(27,7,lightg)

block8 = image.create(27,7,lightg)

block9 = image.create(27,7,lightg)

block10 = image.create(27,7,lightg)

Player = { x = 220 , y = 116}

playerHeight = 20
playerWidth = 20

xpos = 240
ypos = 136
playercolor = color.new(0,0,255)
playerimage = image.create(15, 15)
playerimage:clear(playercolor)


function checkcontrols()
controls.read()
  
if controls.left() and controls.up() then
       Player.y = Player.y + 1.25
       Player.x = Player.x - 1.25
       
   elseif controls.left() and controls.down() then
       Player.y = Player.y - 1.25
       Player.x = Player.x - 1.25

   elseif controls.left() then
       Player.x = Player.x - 1.25
     end  

if controls.right() and controls.down() then
       Player.y = Player.y - 1.25
       Player.x = Player.x + 1.25


   elseif controls.right() and controls.up() then
       Player.y = Player.y + 1.25
       Player.x = Player.x + 1.25

   elseif controls.right() then
       Player.x = Player.x + 1.25 
     end

if controls.up() and controls.right() then
       Player.y = Player.y - 1.25
       Player.x = Player.x - 1.25

   elseif controls.up() and controls.left() then
       Player.y = Player.y - 1.25
       Player.x = Player.x + 1.25

   elseif controls.up() then
       Player.y = Player.y - 1.25
     end

if controls.down() and controls.right() then
       Player.y = Player.y + 1.25
       Player.x = Player.x - 1.25

   elseif controls.down() and controls.left() then
       Player.y = Player.y + 1.25
       Player.x = Player.x + 1.25

   elseif controls.down() then
       Player.y = Player.y + 1.25
     end
end


Block2 = {}
Block2[1] = { x = 0, y = 0, height = block2:height(), width = block2:width() }
Block2[2] = { x = 0, y = 271, height = block2:height(), width = block2:width() }

Block3 = {}
Block3[1] = { x = 0, y = 0, height = block3:height(), width = block3:width() }
Block3[2] = { x = 479, y = 0, height = block3:height(), width = block3:width() }

Block4 = {}
Block4[1] = { x = 45, y = 15, height = block4:height(), width = block4:width() }
Block4[2] = { x = 300, y = 15, height = block4:height(), width = block4:width() }
Block4[3] = { x = 45, y = 195, height = block4:height(), width = block4:width() }

Block6 = {}
Block6[1] = { x = 290, y = 195, height = block6:height(), width = block6:width() }
Block6[2] = { x = 370, y = 195, height = block6:height(), width = block6:width() }

Block5 = {}
Block5[1] = { x = 90, y = 79, height = block5:height(), width = block5:width() }

Block7 = {}
Block7[1] = { x = 355, y = 79, height = block7:height(), width = block7:width() }

Block8 = {}
Block8[1] = { x = 90, y = 188, height = block8:height(), width = block8:width() }

Block9 = {}
Block9[1] = { x = 307, y = 188, height = block9:height(), width = block9:width() }

Block10 = {}
Block10[1] = { x = 387, y = 188, height = block10:height(), width = block10:width() }



function collisionCheck2(block2)
   if (Player.x + playerWidth > block2.x) and (Player.x < block2.x + block2.width) and (Player.y + playerHeight > block2.y) and (Player.y < block2.y + block2.height) then
    Player.x = oldx
    Player.y = oldy
  end
end


function collisionCheck3(block3)
   if (Player.x + playerWidth > block3.x) and (Player.x < block3.x + block3.width) and (Player.y + playerHeight > block3.y) and (Player.y < block3.y + block3.height) then
    Player.x = oldx
    Player.y = oldy
  end
end


function collisionCheck4(block4)
   if (Player.x + playerWidth > block4.x) and (Player.x < block4.x + block4.width) and (Player.y + playerHeight > block4.y) and (Player.y < block4.y + block4.height) then
    Player.x = oldx
    Player.y = oldy
  end
end

function collisionCheck6(block6)
   if (Player.x + playerWidth > block6.x) and (Player.x < block6.x + block6.width) and (Player.y + playerHeight > block6.y) and (Player.y < block6.y + block6.height) then
    Player.x = oldx
    Player.y = oldy
  end
end

while true do

   oldx = Player.x
   oldy = Player.y
   screen.clear()

   checkcontrols()

   if success == 1 then
   
       timer = timer + 1
    if timer > 15 then
       connected = false
        socket.send(socket,"Player.x:" .. Player.x .. "Player.y:" .. Player.y .. "end:")
      timer = 0
      socket.send("check connection")
    end
    recv = socket.recv(socket, 512)
    if string.len(recv) > 0 then
      if recv == "check connection" then
        socket.send("is connected")
      end
      if recv == "is connected" then
        connected = true
      end
      for i = 1, string.len(recv) do
        if string.sub(recv, i - 1, i) == "Player.x:" then
          xstart = i + 1
        end
        if string.sub(recv, i - 1, i) == "Player.y:" then
          xpos = tonumber(string.sub(recv, xstart, i - 2))
          ystart = i + 1
        end
        if string.sub(recv, i - 3, i) == "end:" then
          ypos = tonumber(string.sub(recv, ystart, i - 4))
        end
      end
    end
  end

   
   
   
   collisionCheck2(Block2[1])
   collisionCheck2(Block2[2])

   collisionCheck3(Block3[1])
   collisionCheck3(Block3[2])

   collisionCheck4(Block4[1])
   collisionCheck4(Block4[2])
   collisionCheck4(Block4[3])



   collisionCheck6(Block6[1])
   collisionCheck6(Block6[2])


   background:blit(0,0)


   for a = 1,2 do
     block2:blit(Block2[a].x,Block2[a].y)
   end

   for a = 1,2 do
     block3:blit(Block3[a].x,Block3[a].y)
   end

   for a = 1,3 do
     block4:blit(Block4[a].x,Block4[a].y)
   end

   for a = 1,1 do
     block5:blit(Block5[a].x,Block5[a].y)
   end

   for a = 1,2 do
     block6:blit(Block6[a].x,Block6[a].y)
   end

   for a = 1,1 do
     block7:blit(Block7[a].x,Block7[a].y)
   end
   
   for a = 1,1 do
     block8:blit(Block8[a].x,Block8[a].y)
   end

   for a = 1,1 do
     block9:blit(Block9[a].x,Block9[a].y)
   end

   for a = 1,1 do
     block10:blit(Block10[a].x,Block10[a].y)
   end

   draw.fillrect(10,10,health/4,healthbar,red)

   screen.print(10,30,health,white)

   draw.fillrect(370,10,mana/4,manabar,blue)

   screen.print(370,30,mana,white)

   screen.print(Player.x-8,Player.y-10,name,.6,black,color.new(0,0,0,0))
  
   if connected then
  image.blit(xpos, ypos, playerimage)
  end
  
  player.blit(Player.x,Player.y,player)

   screen.waitvblankstart()
   screen.flip()

   end 
Advertising
qwikrazor87
Guru
Posts: 2874
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA]I'm having an issue with a multiplayer game

Post by qwikrazor87 »

dan369 had a similar issue, he posted a thread here about it.
http://psp.scenebeta.com/node/93301
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
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA]I'm having an issue with a multiplayer game

Post by dragonxtamer596 »

I don't know if this is right but do I just use\/

Code: Select all

wlan.init(int)
Instead?
qwikrazor87
Guru
Posts: 2874
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA]I'm having an issue with a multiplayer game

Post by qwikrazor87 »

I haven't messed with the wlan functions so I'm not exactly sure, but the first arg is the access point you want to connect to, 1 would be the first connection, 2 with be the second connection, etc.. The 2nd arg is the timeout, if you want to set a timeout just enter a number there for how long you want it to attempt to connect to an access point, otherwise leave it empty.
You might be able to use wlan.getconfigs() or wlan.scan() to choose an access point, I'm not sure though.
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
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA]I'm having an issue with a multiplayer game

Post by dragonxtamer596 »

I think it worked but now I actually get an error in the sending/receiving code line 405

Code: Select all

    recv = socket.recv(socket, 512) 
qwikrazor87
Guru
Posts: 2874
Joined: Sat Apr 21, 2012 1:23 pm
Location: The North Pole

Re: [LUA]I'm having an issue with a multiplayer game

Post by qwikrazor87 »

hmm, I never messed around with any net functions so I wouldn't know what to do here.
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
dragonxtamer596
Posts: 188
Joined: Wed Oct 24, 2012 11:49 pm
Contact:

Re: [LUA]I'm having an issue with a multiplayer game

Post by dragonxtamer596 »

I've never been so angry confused disappointed and sad in my whole life lol. Darn.
Post Reply

Return to “Programming and Security”