roomvariable (I guess)Newbie question

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

sandwichs
Posts: 12
Joined: 26 Feb 2006, 04:08

roomvariable (I guess)Newbie question

Postby sandwichs » 08 Mar 2006, 03:11

I have tried to find the answer in the forum and reading the tuts but I can't find the starting point.
I am trying to create a roulette type of game. All players and spectators need to see the ball moving.

what is the best way to accomplish that?

I tried to use RoomVariables but no luck (Of course, I'm not even sure where to put them in the movie). Any help would be appreciated.
Thanks in advance
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 08 Mar 2006, 06:18

Hello,
and welcome.

Not very easy to explain in a few words. I don't know if you are already familiar with multiplayer games however for a roulette game I would reccomend to implement the game logic on the server side.

SmartFoxServer PRO allows to do this easily by using Actionscript 1.0, which is usually a language that Flash developers are familiar with. (If you want you can also use Java)

About the moving ball... if you want to stay simple you could avoid the realistic movement of the ball in the roulette wheel and just highlight each number in the wheel as it spins. I've seen something like this in other similar games.

If you want to show the ball moving and jumping in the wheel then you should first study how to create this in single player mode and then find a suitable way to recreate the motion changes on all the clients.

Since all clients are connected to the game via a server you will have physical limits on the amount of data that you can send and receive, so you want be able to send each and every variation of the motion.

The best idea would be to have a set of random parameters (starting speed, angle, friction...) generated by the server and then each client will reproduce the same animation, based on those initial paremeters.

hope it helps :)
Lapo
--
gotoAndPlay()
...addicted to flash games
sandwichs
Posts: 12
Joined: 26 Feb 2006, 04:08

Postby sandwichs » 09 Mar 2006, 02:40

I wrote the actionscript for the game as far as random movement of the ball and it looks realistic enough(I'm the only player of course). Basically, what I can't understand is how to "send" the y and x coordinate of the ball to the other players. To save bandwidth, I was thinking of sending 2 arrays (the x and y)every second or something like that. But to try that, I first have to know how and where(in the movie) to setup these 2 arrays and how the other players would read them

Thanks for the reply.
louissi
Posts: 48
Joined: 03 Mar 2006, 20:55

Postby louissi » 09 Mar 2006, 02:58

look for the sendObject function in the docs, I think it is what you are looking for.
Sparticus
Posts: 227
Joined: 27 Feb 2006, 17:44
Location: Canada
Contact:

Postby Sparticus » 09 Mar 2006, 15:45

I believe Lapo has the right idea here. I definitely would not send the balls movements to each player.... that would be a crap load of packets getting sent and even small latencies will cause lag in the balls movement. But instead you should send the initial starting speed, angle, starting xy coordinates, etc.... of the ball and once each player receives it, their flash client bascailly "plays it out". Since they are all running the same flash client... and received the same starting data, the ball will follow the exact same path for each player and land on the same number.
sandwichs
Posts: 12
Joined: 26 Feb 2006, 04:08

I understand the send object but..

Postby sandwichs » 10 Mar 2006, 03:18

I understand the send object (i think)

myChar = new Object()
myChar.name = "ball_position"
myChar.position = {px: 100, py:100}

sendObject(myChar)

How do the other players retrieve that object and where?
User avatar
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Postby Virusescu » 10 Mar 2006, 07:53

all users in the room will recieve a onObjectRecieve notice.
You need to define a handler and do your magic inside it

Code: Select all

smartFox.onObjectReceived = function(obj:Object, sender:User)
{
   // Assuming another client has sent his X and Y positions
   // in two properties called px, py

   trace("Got data from: " + sender.getName())
   trace("X = " + obj.px + ", Y = " + obj.py)
}


You will see if you take a better look at the docs for the sendObject method that it states "Fires the onObjectReceived event"
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
sandwichs
Posts: 12
Joined: 26 Feb 2006, 04:08

alright then

Postby sandwichs » 10 Mar 2006, 16:58

didn't find the Fires the onObjectReceived event. in the doc
Thanks for the snipped thought but I still don't where to put it.Sooooo,
Where can I hire someone to write the code?
User avatar
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Postby Virusescu » 12 Mar 2006, 17:34

you can contact me at yahoo Id ady_the_virus on messenger. But it all depends on how much are you willing to pay and how fast do you need it. If you are patient enough you will find help in the end on the forums ;). Have a look at the other thread, I wrote you a reply already.
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 37 guests