Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Timer and real time accuracy

Posted on 2011-02-25
13
541 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
ID: 34985478
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
ID: 34987526
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
ID: 34989924
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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
LVL 12

Expert Comment

by:satsumo
ID: 34990005
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
ID: 34990127
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
ID: 34995093
@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
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34995193
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
ID: 34996259
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
ID: 34997131
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
ID: 34998214
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
ID: 35004430
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
ID: 35005851
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
ID: 35013837
Yeah, your right. I would just want to hide the answer. Will look into the links provided. Thanks.
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to count occurrences of each item in an array.

860 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