Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing php variables into html5 2

Status
Not open for further replies.

ralphonzo

Programmer
Apr 9, 2003
228
GB
Does anyone know how to pass php variables into html5 and back again so that I can utilise the data into animations? Is this the best thing to do, or am I missing some newer technology??
 
What's your aim? You want php to control an animation on the client side? It's better to control the animation fom the client side, not from the server side? Is there any need to control it from the server side? What does only the server know and cannot hand out to the client at the start of an animation? Is this about game play? multiplayer life, where the server needs to update positions of all player in each players client?

You can use the classic xmlhttprequest from within a javascript client side program to request other players data by polling it in a timer or using "long-live" ajax requests you keep open all the time.

As you aim for html5, make use of websockets as full duplex connections from client to server. Read further details here:
But in the simpler cases you want to display some animation, just display a video or animated gif and don't need any further control from client or server side.

Bye, Olaf.
 
Thanks Olaf. What I really need to do is to grab a bunch of information (for each race that will be run in the game I'm developing) from the database, manipulate it in client side and store the results so that they can be drawn out again in the form of a dynamic animation. I'll have a look AJAX. I've never done any HTML animations before, so I'm getting ready for some serious head scratching!!

Something else I need to try to get my head around too is real-time updating. What's the best way to get the races to run? Have a machine with browser open humming along in my room, rely on game users to power it, or some other dark art??
 
I recommend you start with something simpler. For example take a look into javascripts moving around some graphics reacting to mouse moves, this has no server side processing involved whatsoever, but answers your question on how to get something to run in the first place:

[URL unfurl="true"]http://www.google.de/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CC0QFjAA&url=http%3A%2F%2Fwww.javascript-fx.com%2Fsubmitscripts%2Fmouse_squidie%2Fdemo1.html&ei=S2k7UI2AMcPZtAbsx4DYDA&usg=AFQjCNEZMFtkIzppvwnCdJeRRho4v4kkjA&cad=rja[/url]

Also be warned, that this is not as easy as it seems, also forget about websockets, as even IE10 will not yet support them.
AJAX is not easily learned by writing a game. Better start with a single user version of the game, that doesn't need server interaction.

This is a javascrtipt task, not a PHP task. The only thing your server does is bring the javascript to the client, as you do with HTML, afterwards, the server is not involved any more unless you need synching of multiple users racing on the same racing track. And then an even more common language to develop such games would be flash, not javascript and not php.

Bye, Olaf.
 
Thanks Olaf. I'm getting away from Flash nowadays, as I want more cross browser/platform option. Haven't done any Javascript programming in years - I can't say I'm looking forward to it :eek:)

Thanks for your pointers,

Enjoy the star,

Ralph
 
These races will run at set times though. Each one needs to run regardless of whether someone clicks to run it or not. How would you suggest getting around that?
 
I don't get you, sorry. If nobody plays a game, nobody plays a game.

Thanks for the star, anyway. I think you'll like what you can do wih todays javascript libraries. There are very many different flavours, first concentrate on the core ajax principle perhaps.

But if no interaction is involved and players merely watch a race going, that would mean you calculate through several probabilities and let a race go through several stages you only want to display? If everything else fails all you need to do is prerun the race on the server side and feed a javascript with the progress of a race. to show it.

Or do you talk about a real race, as a horse race or formula one and you merely want to display a ranking list, which updates automatic?

It all depends on my or our understanding to give you the correct pointers.

Bye, Olaf.
 
I understand your confusion - I'm confused with which path to travel, so it's awkward to get my exact meaning across. I might be asking you something that's so obvious to you that I already haven't grasped the concept :eek:)

OK, all races need to be run a pre-determined times. Some of the races will go along (especially at first before many users interact) without users watching them, but the results need to be posted anyway. So for example, if ten races have past unwatched client side, the machine of the first user to log in will have a massive backlog of data to collate. Also, if a user logs into a race whilst it's half way through...aaargh! Nightmare. I need the races (and training updates) to run on the server somehow, then grab the data (the same for everyone) onto the client side. I've only ever run things in PHP and ASP that process the run-time information through browser interaction. Is it possible for this type of thing to run independently on the server?

Sorry to be such a numpty,

Ralph
 
Well, depends (when does it not). Let me make some assumtions. Assume there is a track and racers have their starting positions, computer AI is controlling racers and so you have lots of data about how the race develops from start up to a current moment. But what is characteristic for a certain moment? The position and speed of racers on the track. All other data is of no interest any more, is it?

So each user coming in late, taking over his racer, which raced by AI so far, only needs to know track, racer positions and speed to begin displaying the race and continuing it. Isn't that so?

You need that info anyway to display the current situation of the racde to anyone, even the players using the game from start.

Bye, Olaf.
 
I'd rather not put constant send/receive pressure on the server. If each race could be determined prior to the actual start time, then anyone could run the full race at or after that moment. I suppose I could batch run a week's worth of races via an admin panel?? But that would predispose that all the info was available at that time, which would negate the possibility of late entrants/withdrawals. Thought I had it then!! Any ideas?

Regards,

Ralph
 
Well, you can mix both strategies, like in videos having mainly two types of frames: Some frames with a current picture and some frames only containing delta to previous frames. In terms of your races data to describe how racers are moving and positional data. The one computes from the other, you can start watching a race late by starting at the nearest positional data and then let the browser play the predetermined moves.

If races are really fully predetermined, why not make the poisiotns of grphics the race data, you can start at any point and just "play" the rest of it.

Bye, Olaf.
 
But it's the issue of how (and where) the race data are determined in the first place. Is it possible to run these on the server somehow, without any browser intervention? If so, how?
 
Well, the outset should not differ much in each game,and then you have your game logic.

So if you take it for granted javascript is the only language of choice on the client side, are we at the question of running javascript serverside?

Maybe, but if running a game server side, you just need to take the core code of computing racer positions, and you can do that without a timer. It's mainly a very tight loop with some math/physics in the range of accelleration = acceleration + userinfluence(keyboard/mouse), velocity = velocity +acceleration/frame, postion = position + velocity/frame. That's some math you can do both in javascript and php, can't you? That oversimplification, you have to take into account driving off track and collisions. All this you should implement to be able to check it without any UI.

That's the same seperation of logic and presentation you do in business applications. It's always a good idea to keep tiers completeley independant.

Bye, Olaf.
 
Hello Olaf,

I've already got the logic and mechanics sorted, I just don't know how it's all going to work at the allotted time on the server. On a browser, no problem, but I have no idea how this can be implemented if no browser window is open triggering the activity. In other words, how does one run a script actually on the server at a predetermined run time?
 
but I have no idea how this can be implemented if no browser window is open triggering the activity
You can't, HTTP is a disconnected/stateless protocol, if a client does not make a request ... nothing happens. To make what you want work you would need a 'listener' ie: A daemon(Linux/Unix) or a service(Windows) installed and running on your server.
Using Java, which can make continual server requests without crashing the browser when it runs out of memory, would be the better way to go.

And of course ActionScript (Flash) can also do such things


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
That's what I'm after, brilliant, thank you, and have another star :eek:)
 
I woul go about it this way: The first time some game data of an already started game is queried, you compute all game data up to the current time. You don't need much time for it, so you can also do it "just in time", it doesn't needs to be done at a predetermined time.

And if no user ever loads a game and only looks into results, you can go about it in the same way, computing the full game to watch.

The data only is needed, if it's queried, it doesn't need to be computed, if noone watches.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top