These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

advice / help wanted from javascript expert for new 3rd pary app -- javascript synchronization??

Author
Eve Industrialist
Eve industRIaliSt - Dot Com
#1 - 2011-11-27 23:17:50 UTC
Hello

I am creating a silly toy where i am trying to adapt a text-based MUD (multi-user dungeon) from pre-internet days (that has some similary to eve) to work in the eve browser so you can play it with your eve character in the in-game browser while playing eve.

It sort of works:

https://eve-industrialist.com/eve-trade-wars/start.eve

Sadly the javascript end of it has left me puzzled due to the fact that javascript doesnt' have a "synchronized" function.

I use onkeypress() to send data the user types to the back end, which writes it to the socket to the game server. The problem is that i need to immediadtly read from said socket, and also periodically check for input from the socket, but i can't do both at once because then both calls try to update the screen at once and you get a mess. or you get an inconsistant state and it all freezes. I tried only reading from the socket periodically but that creates intolerable "lag".

I mostly code these things to learn more and better programming that i would taking IT on-line classes, and i have never interacted with more intelligent programmers than i have through eve. That is why I am coming here to ask for help even though this is not directly eve api related. I'm sorry if i'm taking up space or wasting anyone's time.

I have considered buffering the user input in the javascript, trying to do synchronization on the back end and polling the back end very frequently, but not sure if iether of those are solutions. Maybe there is a library / api everyone knows about except me that does this for me?

Please let me know if i can contact you in-game about this.


Cyna
CynaCorp
#2 - 2011-11-28 02:02:08 UTC
Eve Industrialist wrote:
Hello

I am creating a silly toy where i am trying to adapt a text-based MUD (multi-user dungeon) from pre-internet days (that has some similary to eve) to work in the eve browser so you can play it with your eve character in the in-game browser while playing eve.

It sort of works:

https://eve-industrialist.com/eve-trade-wars/start.eve

Sadly the javascript end of it has left me puzzled due to the fact that javascript doesnt' have a "synchronized" function.

I use onkeypress() to send data the user types to the back end, which writes it to the socket to the game server. The problem is that i need to immediadtly read from said socket, and also periodically check for input from the socket, but i can't do both at once because then both calls try to update the screen at once and you get a mess. or you get an inconsistant state and it all freezes. I tried only reading from the socket periodically but that creates intolerable "lag".

I mostly code these things to learn more and better programming that i would taking IT on-line classes, and i have never interacted with more intelligent programmers than i have through eve. That is why I am coming here to ask for help even though this is not directly eve api related. I'm sorry if i'm taking up space or wasting anyone's time.

I have considered buffering the user input in the javascript, trying to do synchronization on the back end and polling the back end very frequently, but not sure if iether of those are solutions. Maybe there is a library / api everyone knows about except me that does this for me?

Please let me know if i can contact you in-game about this.




I assume you're doing your calls through AJAX, if you are, then you can just buffer everything the user is typing until they hit enter, then make an AJAX call to your system with the user input, in the meantime, to receive updates FROM the server, you can have a timed AJAX call running every X seconds to fetch any new buffered data from the server.

Love EVE, love the environment, (most of) the players, and the programming! My projects: EVE POP3 Mail Service

Eve Industrialist
Eve industRIaliSt - Dot Com
#3 - 2011-11-28 02:17:21 UTC
Cyna wrote:


I assume you're doing your calls through AJAX, if you are, then you can just buffer everything the user is typing until they hit enter, then make an AJAX call to your system with the user input, in the meantime, to receive updates FROM the server, you can have a timed AJAX call running every X seconds to fetch any new buffered data from the server.



Yes, but the Enter key is a problem in itself, as the socket program sometimes wants to see enter (when the user types a word or on a couple of commands) but it usually does not (asks for a range of commands and acts upon recieving one).

So i need to send all the enter keys the user types to the server, and send input to the server without enter key.

This is a very old program invented before the internet was invented. It works perfectly on a console...


Buffering the data is a good idea. I'm debating buffering data that the user types in quickly (say a whole word) and using the time between 2 inputs to determine when to send it (what you suggest for enter key -- no user input for 1 or 2 sec? send it.) but that seems way too complex for javascript that's cracking up on me already. maybe there is a better solution involving buffering.

you can see all the javascript i have on the link there once you click 'play' -- it works for a bit then gets at times stuck. server sends correct responses all the way though. It's javascript that's failing.