forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WLAN Multiplayer?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
Kakolukia



Joined: 11 Jun 2006
Posts: 21

PostPosted: Thu Jun 15, 2006 4:51 pm    Post subject: Reply with quote

Altair wrote:
Yes what you did is the same as what i did.

I didn't know the command tonumber existed. Thx for that!


That's what I thought, saves us a lot of code!

But if I want to send an x and an y (and more), what would be the best way to do this?

make 1 long string of, and cut it in pieces at the other psp?
or send them seperatly? But how does the other psp know which is the x and y?
Back to top
View user's profile Send private message MSN Messenger
Altair



Joined: 20 May 2006
Posts: 76
Location: The Netherlands

PostPosted: Fri Jun 16, 2006 1:53 am    Post subject: Reply with quote

Hmm yeah, i guess still use one big string and then cut it into pieces. So it still doesnt help to much, the "tonumber" command.
Back to top
View user's profile Send private message
Kakolukia



Joined: 11 Jun 2006
Posts: 21

PostPosted: Fri Jun 16, 2006 2:50 am    Post subject: Reply with quote

Altair wrote:
Hmm yeah, i guess still use one big string and then cut it into pieces. So it still doesnt help to much, the "tonumber" command.


maybe be2003 knows how to solve this in a smooth way too...
Back to top
View user's profile Send private message MSN Messenger
SSpeare



Joined: 23 May 2006
Posts: 63

PostPosted: Fri Jun 16, 2006 3:32 am    Post subject: Reply with quote

You could build a string like this:

Code:

-- Assuming:
x = 45
y = 56
-- Do this:
send = x.."^"..y
-- Now send = "45^56"


And then parse it like this:

Code:
x = tonumber(piece(data,"^",1))
y = tonumber(piece(data,"^",2))


If you use a function "piece" like this:

Code:

function piece(str,delim,num)
   if num < 1 then
      return ""
   end
   local lastEnd = 0
   local matchBegin,matchEnd = string.find(str,delim,1,true)
   local loop = 1
   for i=2,num do
      loop = i
      lastEnd = matchEnd
      matchBegin,matchEnd = string.find(str,delim,matchEnd+1,true)
      if (matchBegin == nil) then
         matchBegin = string.len(str)+1
         break
      end
   end
   if num > loop then
      return ""
   end
   return string.sub(str,lastEnd+1,matchBegin-1)
end



You could use anything instead of "^", that's just an example. And you can put more data in there. As much as you want. The piece function is kind of wasteful if you are getting lots of data out, but it works. If you want it to be more efficient you could use a Tokenizer pattern or something.


Last edited by SSpeare on Fri Jun 16, 2006 7:18 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Kakolukia



Joined: 11 Jun 2006
Posts: 21

PostPosted: Fri Jun 16, 2006 5:30 am    Post subject: Reply with quote

there is a lot of new code for me in that, but I will look into it later, maybe tomorrow, got some stuff to do now...
But thanx for the help!
Back to top
View user's profile Send private message MSN Messenger
be2003



Joined: 20 Apr 2006
Posts: 144

PostPosted: Fri Jun 16, 2006 7:21 am    Post subject: Reply with quote

... sending coordinates...
first define ur x and y
x = 2
y = 5
then make em one string separated by a comma
coXY = tostring(x)..","..tostring(y)
send it
System.irdaWrite(coXY)

on the receiving end
oppcoXY = System.irdaRead()
blah blah blah, just receive the string like normal ok

make a fuction to turn it back
function parseXY(oppcoXY)
for i=1, string.len(oppcoXY) do
char = string.sub(oppcoXY,i,i)
sy = ""
sx = ""
tempxory = "x"
if char == "," then
tempxory = "y"
elseif tempxory == "x" then
sx = sx..char
else tempxory == "y" then
sy = sy..char
end
end
oppx = tonumber(sx)
oppy = tonumber(sy)
end

this function takes i the received string and writes the vars oppx and oppy to the ram and can be accessed anytime if they arent changed to something else.
_________________
- be2003
blog
Back to top
View user's profile Send private message
Altair



Joined: 20 May 2006
Posts: 76
Location: The Netherlands

PostPosted: Fri Jun 16, 2006 10:37 am    Post subject: Reply with quote

Ok thx. So its basicly what we already did but then with the addition of tonumber() (which makes stuff easier though)
Back to top
View user's profile Send private message
Kakolukia



Joined: 11 Jun 2006
Posts: 21

PostPosted: Sat Jun 17, 2006 3:18 am    Post subject: Reply with quote

Altair wrote:
Ok thx. So its basicly what we already did but then with the addition of tonumber() (which makes stuff easier though)


yeah, pretty kewl community out here, there really helpfull, thanx to anyone who helped us out!
Back to top
View user's profile Send private message MSN Messenger
Kakolukia



Joined: 11 Jun 2006
Posts: 21

PostPosted: Sat Jun 17, 2006 3:40 am    Post subject: Reply with quote

Quote:

if char == "," then
tempxory = "y"
elseif tempxory == "x" then
sx = sx..char
else tempxory == "y" then
sy = sy..char
end


shouldnt it be an "elseif" or an "=" instead of an "else" or "=="???


Last edited by Kakolukia on Sat Jun 17, 2006 7:16 am; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
Altair



Joined: 20 May 2006
Posts: 76
Location: The Netherlands

PostPosted: Sat Jun 17, 2006 4:08 am    Post subject: Reply with quote

yes it has to be "elseif"
Back to top
View user's profile Send private message
Kakolukia



Joined: 11 Jun 2006
Posts: 21

PostPosted: Sat Jun 17, 2006 4:26 am    Post subject: Reply with quote

figured it out, = gives an error, but you probably tried it too, and found out ;)
Back to top
View user's profile Send private message MSN Messenger
be2003



Joined: 20 Apr 2006
Posts: 144

PostPosted: Mon Jun 19, 2006 2:30 pm    Post subject: oops Reply with quote

the function should work if you define sx, sy, and tempxory before the whole "for i=..." or else everytime the for command makes a cycle then the vars get reset. sorry
_________________
- be2003
blog
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group