gumshoe2029's Recent Forum Activity

  • It is definitely possible, but you will probably have to find and integrate an outside library.

    Some other folks in the computer world have tried:

    https://www.reddit.com/r/javascript/com ... avascript/

    https://github.com/mpberk/Pedometer

    https://github.com/leecrossley/cordova-plugin-pedometer

  • I am not sure this is possible. The user will have to manually delete the save, I believe.

    Are you using nw.js? Or raw JS?

  • R0J0hound has a draw_line.capx that did more or less what you want.

    I lost his post, but the capx is here: https://drive.google.com/file/d/0B-xiqK ... sp=sharing

  • Which server are you pinging? What is the domain URL?

  • Make sure you implement object oriented principles in your code. Otherwise you will end up with a tightly integrated system with unmaintainable code and where bugs propagate wildly through your code.

    http://searchsoa.techtarget.com/definit ... rogramming

    https://docs.oracle.com/javase/tutorial/java/concepts/

    Subscribe to Construct videos now
  • You may potentially need a backend programming language too, like PHP, Python, or Java. Something for Construct to talk to.

    If you are hell-bent on connecting to a database using JavaScript, it is possible but not recommended.

    http://stackoverflow.com/questions/8576 ... he-browser

    PHP is by far the easiest server-side language to learn though and Google has tons of resources.

    https://www.google.com/search?q=javascr ... e+tutorial

  • Yea, what you are asking is called "maintaining game state."

    How we do this is with Java servlets that all operate on the basis of one database that maintains all of the game state. From here our API program dips into the database and gives information to each client.

  • http://stackoverflow.com/questions/1711 ... /1713#1713 has a good list.

    The books on that list that have been recommended to me by other software engineers include:

    Design Patterns by the Gang of Four

    Mythical Man Month

    Thinking in Java by Bruce Eckel

    Effective Java by Joshua Bloch

  • RIght. You can do more than just distribute HTML files. We have an entire backend Java servlet system running. Around 20,000 lines of server-side code right now.

    SmartFox is an option, but I prefer AWS because they offer us more capability than SF.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Oh... I was under the impression that you already had a personal license...

    You should definitely look at getting a personal license at a minimum. It is well worth it.

  • I suspect the problem is on your server code, not your Construct2 code. Did you look at that example?

  • var WebSocketServer = require('ws').Server

    , wss = new WebSocketServer({port: 8080});

    wss.on('connection', function(ws) {

    ws.on('message', function(message) {

    console.log('received: %s', message);

    });

    ws.send('something');

    });

    The one main problem that I see right off is that you rolled your onmessage method into your onconnection method.

    Those two need to be separate functions, like:

    var WebSocketServer = require('ws').Server, wss = new WebSocketServer({port: 8080});
    
    wss.on('connection', function(ws) {
            ws.send('Connected.');
     });
    
    ws.on('message', function(message) {
            console.log('received: %s', message);
                ws.send('Message received.');
        });
    [/code:2jwc88p6]
    
    You also need to make sure that you have the "Access-Control-Allow-Origin" header set to '*'  because Construct is very particular about security, and your websockets will not work if that header is not set on the server side.
    
    See this example for more info: [url=http://usualcarrot.com/nodejs-and-websocket-simple-chat-tutorial]http://usualcarrot.com/nodejs-and-webso ... t-tutorial[/url]
    
    You can see the compartmentalization in my Java WebSocket server code below:
    [code:2jwc88p6]
    public GalaxyChatEndPoint(){
        	mLog = new MessageLogManager(filePath, fLogger, SP);
        }
        
        /**
         * Callback hook for Connection open events. This method will be invoked when a
         * client requests for a WebSocket connection.
         * @param userSession the userSession which is opened.
         */
        @OnOpen
        public void onOpen(Session userSession){
        	try{
        		userSession.setMaxIdleTimeout(600000);//10 mins
            	sessionKey = ((PrincipalWithSession) userSession.getUserPrincipal()).getSessionKey();
            	gameSession = cache.get(sessionKey.getKey());
                connections.put(sessionKey, userSession);
                if(gameSession==null)
                	broadcast("<p>gumshoe joined chat.</p>");
                else
                	broadcast(String.format("<p>%s%s</p>", gameSession.getDisplayName()," joined chat."));
        	}catch(Exception e){
        		fLogger.error(Errors.err2String(e));
        		try {
    				connections.get(sessionKey).close();
    				connections.remove(sessionKey);
    			} catch (IOException e1){
    	    		fLogger.error(Errors.err2String(e1));
    			}
        	}
        }
         
        /**
         * Callback hook for Connection close events. This method will be invoked when a
         * client closes a WebSocket connection.
         * @param userSession the userSession which is opened.
         */
        @OnClose
        public void onClose() {
        	try{
        		if(gameSession==null)
        			broadcast("<p>gumshoe left chat.</p>");
        		else
        			broadcast(String.format("<p>%s%s</p>", gameSession.getDisplayName()," left chat."));
    			connections.get(sessionKey).close();
    			connections.remove(sessionKey);
        	}catch(Exception e){
        		fLogger.error(Errors.err2String(e));
        		try {
    				if(connections.get(sessionKey)!=null)connections.get(sessionKey).close();
    				if(connections.get(sessionKey)!=null)connections.remove(sessionKey);
    			} catch (IOException e1){
    	    		fLogger.error(Errors.err2String(e1));
    			}
        	}
        }
         
        /**
         * Callback hook for Message Events. This method will be invoked when a client
         * sends a message.
         * @param message The text message
         * @param userSession The session of the client
         */
        @OnMessage
        public void onMessage(String messageJson) {
        	try{
        		Date now = new Date();
        		String dateFmt = new SimpleDateFormat("EEE MMM HH:mm:ss z yyyy").format(now);
        		Message message = Message.fromJson(messageJson, gameSession);
        		globalMessageLog.put(currentMessageId.incrementAndGet(), message);
        		if(message.getDestination().getDestType()==DestinationType.GALAXY)
    	    		if(gameSession==null)
    	    			broadcast(String.format(galaxyChatFramework, dateFmt, "gumshoe", message.getContent()));
    	    		else
    	    			broadcast(String.format(galaxyChatFramework, dateFmt, gameSession.getDisplayName(), message.getContent()));
        		// this may need to be reworked...  perhaps to a raw message number system
        		Date time1159pm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(new SimpleDateFormat("yyyy-MM-dd").format(now) + " 23:59:58");
        		
        		if(now.after(time1159pm)){
        			if(mLog.writeFile(globalMessageLog, now)){
        				globalMessageLog.clear();
        				currentMessageId.set(0);
        			}
        		}
        	}catch(Exception e){
        		fLogger.error(Errors.err2String(e));
    			try {
    				connections.get(sessionKey).close();
    				connections.remove(sessionKey);
    			} catch (IOException e1){
    	    		fLogger.error(Errors.err2String(e1));
    			}
        	}
        }
        
        private static void broadcast(String msg) throws Exception {
        	for(Session client : connections.values()){
        		synchronized (client) {
            		if(client.isOpen()) client.getBasicRemote().sendText(msg);
        		}
        	}
        }
    [/code:2jwc88p6]
gumshoe2029's avatar

gumshoe2029

Member since 4 Mar, 2014

None one is following gumshoe2029 yet!

Trophy Case

  • 10-Year Club
  • Email Verified

Progress

11/44
How to earn trophies