Solved

Timer and real time accuracy

Posted on 2011-02-25
13
510 Views
Last Modified: 2013-11-19
Hi,
I want to create a simple game that gives out 2 random numbers (timer starts), and the user will need to total up and provide the answer. As soon as the user click "enter", the timer will stop and capture the timer(left) in real-time.

And all these are done through a webpage. What is the best technology to use?

Some thought?
1) ASP.net - this is server side. Not sure it will be real time as the lagging time from client to server after click

2) Javascript - user can see the code used, even though i think it can provide real time timer capture.

3) Flash?? or any other ?

0
Comment
Question by:tangteng78
  • 4
  • 4
  • 3
  • +1
13 Comments
 
LVL 17

Expert Comment

by:deepanjandas
Comment Utility
Keeping in mind your requirements, flash would be the best option.

But if someone wishes to hack swf, even it can be done using decompilers but that would not be worth it :)

So you may go forward with flash.

The only think is that the user needs to be have a flash player installed.

Javascript, apart from security may get blocked in some user settings due to protection.

Warm Regards
Deepanjan Das
0
 
LVL 12

Expert Comment

by:profgeek
Comment Utility
Not all users enable flash either, so it seems that if you want to address all users, you'll need to use a server-side solution or perhaps a combination of the two.  Can you create most of the app in ASP or PHP and then deliver only the timer functionality in Javascript?
0
 
LVL 17

Expert Comment

by:deepanjandas
Comment Utility
As per stats almost 98% web users have flash player installed. Also a server side solution is not at all recommended in such cases due to time lag in post back.

So either javascript or flash.

My suggestion is to go with flash.

Warm Regards
Deepanjan Das
0
 
LVL 12

Expert Comment

by:satsumo
Comment Utility
I agree, server side is a bad idea.  There is no way to control the timing from server to client and it's likely to be very unpredictable.  Like deepanjandas, I'd suggest either Flash or Javascript.  Flash is available in the vast majority of browsers as is Javascript.  The Apple handheld devices are the only things that don't support Flash.

Actionscript (the programming language of Flash) and Javascript are very similar languages, both use ECMA script syntax, ActionScript was designed to be like JavaScript.  The game you describe is simple and won't be especially hard in either language.  Is it really worth protecting?  If that is important to you then Flash is significantly harder to get at than Javascript, though it isn't completely secure.

Personally, I'd use Javascript because it's much easier to develop for.  Javascript requires a text editor and a browser.  All the major browser have Javascript debuggers, Firefox has the Firebug plugin, Chrome and IE have built in Javascript debuggers.

Flash development requires downloading many programs, and possibly buying software from Adobe.  A debug version of Flash, an Actionscript complier and a Flash debugger program, etc.  Most of these are quite heavyweight programs too.  As an experienced programmer I don't find Adobe's developer tools friendly or efficient.  Flash also has more of a learning curve.  I prefer Adobe Flex when building Flash apps.
0
 
LVL 12

Expert Comment

by:profgeek
Comment Utility
Is latency really an issue in the game that is described here?  It sounds like you just want to deliver a problem and time the solution.  
0
 

Author Comment

by:tangteng78
Comment Utility
@profgeek:

Yes, the latency is important, as i need to 'capture' in real time mode the second/milisecond as soon as the user click on a button.

My 'game' would have few questions, would there be a lag when moving to next question (loading the math-question from the server)?


@deepanjandas/@satsumo:
Is FLASH running on client side?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 17

Expert Comment

by:deepanjandas
Comment Utility
If the questions are from server, yes there might be a time lag based on bandwidth.

Yes flash is client side.

Warm Regards
Deepanjan Das
0
 
LVL 12

Expert Comment

by:satsumo
Comment Utility
Yes, Flash is client side.

Flash and Javascript both have mechanisms for requesting data directly from a server, if that's a factor.  Javascript has XMLHttpRequest, Flash has a few methods, XMLSockets closely resembles the Javascript equivalent.  The question data doesn't have to be stored in the program itself, and the server can choose to send whatever data if it wants.

Of course, that introduces the potential latency again.  You could request all of the question from the server before you begin timing, or ask for the next question while the user is answering.

Perhaps the distinction lies in the interface.  Flash operates in its own box on a page, Javascript uses the HTML objects of the page itself.
0
 

Author Comment

by:tangteng78
Comment Utility
If i were to use javascript, is there a way i can use the server to send the 2 random numbers and the answer to the client without the user can see it by 'view source' on the browser?

Else, it would defeat the game purpose if the user is able to easily 'view' both the random numbers and answer at the same time.

0
 
LVL 12

Expert Comment

by:satsumo
Comment Utility
Yes, the script would request a question from the server.  The response is text, which is stored in a variable, the script can parse and evaluate the text into numeric variables.  The server could send the correct answer in the message, or the script could calculate the answer rather than storing it in a variable.  The script could even send the answer to the server and let the server check.  The issue is that any dealing with the server is introducing potential latency.

Given the way Javascript works, the server could actually send the whole calculation as text.  For example the server might send "(8 + 4) / 2", put that text into Javascript's eval() function and it will return 6.  I'm pretty sure Actionscript does the same thing, deepanjandas would know better than me, Flash can do the same server messaging.

So assuming you had the answer in a variable called 'answer' and the question text in a variable called 'question' the source of the page would contain this.

if (answer == eval (question))
{
    // do something in here
}

Open in new window

I suppose an extremely computer literate could debug the Javascript and see the variables containing the numbers.  You don't have to store the answer in a variable, if it can be calculated every time the answer is tested.  It's harder to debug a Flash app, but it is possible.
0
 

Author Comment

by:tangteng78
Comment Utility
Hi Satsumo,
How does the variable question will get the text from the server (for the eval function) without the user able to view the value of the question (in this case, a string/text) by just right click view source?

The usual way that i would do is for the server to assign/pass the value to a DOM (label..etc) that is hidden, and the javascript to grap the value by using document.getElementID. But by right click + view source, the value would be visible to the user

Is there any other elegant way to get around this?
0
 
LVL 12

Accepted Solution

by:
satsumo earned 500 total points
Comment Utility
When using XMLHttpRequest, the text of the servers response is stored in a property of the request object called responseText.  The text does not appear in the page source, the script would need to deliberately modify the page for the user to see it.

http://www.w3schools.com/dom/dom_http.asp
http://www.w3.org/TR/XMLHttpRequest/
http://www.w3schools.com/dom/tryit.asp?filename=try_dom_xmlhttprequest_first

I didn't think it would matter if the user could see the question.  Doesn't the page shows them the question?  I would imagine you want to hide the correct answer.
0
 

Author Comment

by:tangteng78
Comment Utility
Yeah, your right. I would just want to hide the answer. Will look into the links provided. Thanks.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now