Live Scoreboard

I’m writing a live scoreboard in Xojo, I’ve had a play and come up with something that works by using a webtimer which fires every 100ms (ModeSingle).

The reason I have the timer going off every 100ms is to update the page as there is a running clock which is Min:Sec.Hund

What the webtimer action event does is


Dim SCBData As ScoreboardDataClass

 ' Fetch Scoreboard Data
 SCBData = App.ScoreboardData

' Update Form, Name, Time etc
xxxxxx

' Reset Timer
  tmrUpdatePage.Reset

When running in debug the running time is for example , 1:01.10, 1:01.20, 1:01.30 which is what I expect, when viewing over the web it jumps about 1:01.10, 1:01.90, 1:02.40. I don’t have so much of a issue with that.

What I’m worried about is the amount of processing power being used to just run 10 of these is about 40%

Is there a better way of doing this i’m new to Xojo, we could be looking at 100+ users

[quote=117955:@Graham Spratt]I’m writing a live scoreboard in Xojo, I’ve had a play and come up with something that works by using a webtimer which fires every 100ms (ModeSingle).
The reason I have the timer going off every 100ms is to update the page as there is a running clock which is Min:Sec.Hund
What I’m worried about is the amount of processing power being used to just run 10 of these is about 40%
Is there a better way of doing this i’m new to Xojo, we could be looking at 100+ users[/quote]

First remark : do you really need a precision to the hundred of a second ? Usual digital clocks update every second only. Without changing your code, you would gain 100 times processing power just by changing the timer period.

Second remark : Xojo code executes on the server. To display anything takes sending new informations to the browser, and given Internet technology (not synchronous) updating every 1/100 th a second is nearly impossible, as you have already discovered. You may be waisting processing time. Even if you want to display hundreds of a second, it could be OK. To update at the rate used by movies of every 1/25 th a second.

Not WE guy here but Xojo seems need to implement client/server side code distinction with transparent remote access.

So your score update would run on client side showing min:sec:hundreds

Things like (notice the keywords server/client):

[code]Client Class MyTimer // Defaults all properties and method target to client side except when explicit server side
// A Server Class would be the inverse

Property aDateTime As Date

Sub TryToSynchTime() // Runs on client
aDateTime = getServerTime() // RPC, call this in the server, and return the value to the client side property

End

Server Function getServerTime() // Runs on server
Dim d as New Date
Return d
End Function

Sub UpdateScreen // Client side – You can call it hundreds of times per second and no server trip occurs
Window1.Label1.Text = myFormatedCurrentTime() // Ch
End

… // More methods, properties, event handlers, whatever…

End Class[/code]

The simplest way to have execution on the client is to use a WebTimer :
http://documentation.xojo.com/index.php/WebTimer

You’ll be better off just pushing data whenever a score change occurs. Having something that acts like a live clock would work much better as a client only control, but you would need to use the WebSDK to create that. Basically, you’d need to send the current time from the server when the session starts and then rely on the clock on the client’s computer to keep it up to date.

http://www.java-scripts.net/Javascript-Clocks
http://www.elated.com/articles/creating-a-javascript-clock/
http://www.elated.com/res/File/articles/development/javascript/creating-a-javascript-clock/clock.html
http://www.bloke.com/javascript/Clock/

Thanks guys, from what I understand the best way of having a running clock would be to use javascript and push to the client when to start it.

For example if I wanted this http://www.java-scripts.net/javascripts/Stop-Watch-Script.phtml how would I go about adding that so that it updated a label?

[quote=118009:@Graham Spratt]Thanks guys, from what I understand the best way of having a running clock would be to use javascript and push to the client when to start it.

For example if I wanted this http://www.java-scripts.net/javascripts/Stop-Watch-Script.phtml how would I go about adding that so that it updated a label?[/quote]

Use a WebSDK HTMLArea in which you simply load the script phtml file and use it as is, or modified to suit your requirements. Documentation for the WebDSK is in a folder inside the Extras folder, next to the Xojo executable.

I’ve had a play with the WebControlWrapper and not got very far.

I’ve managed to do a test with

setupHTML

  dim sa() as string
  
  sa.Append "<div id=""p1"">"
  sa.Append "</div>"
  
  return join(sa,"")

and using LoadLibraries change p1 to HELLO

[code]XojoCustom.example.loadlibrary.myFunction = function() {

document.getElementById(“p1”).innerHTML = ‘HELLO’;

}
[/code]

I’m not really sure how to go about add custom javascript and advise would be appreciated.

I have ready over the SDK docs and looked at the examples but don’t think any of the examples are doing what I need.

If I could replicate the below where it start on page load that would be a start

[code]

[/code]

Xojo has a push method which would auto-update the score when it changes. The push would come from the main admin/server session, and auto update the client sessions.

I’ve got the push working for the rest of the scoreboard e.g names, times, etc.

I have tried pushing the running clock from the server but it suffers the same issue as my original post, e.g 1:00.1, 1:00.7, 1:01.2 in a idle world I would like 1:00.1, 1:00.2, 1:00.3 and so on. I’m hoping this javascript clock idea will solve this only issue at present is trying to implement it which I can trigger a start by a push from the server.

Here is how to use the clock snippet without any JavaScript programming:

  • Paste it and save in a text file called clock.html
  • Drag this file into your project
  • Place a WebHTMLViewer on your webpage
  • In the WebHTMLViewer open event enter :
me.loadpage(clock)

That’s it. You will have the timer field and the start/stop and reset buttons on your screen.

This works for most bookmarklets and let you easily incorporate small web pages containing JavaScript as part of your WebPages.

Use a WebStyle with transparent borders and transparent background to be able to place the HTML controls over any background of your choice, including a picture.

Here is the script modified to start by itself upon load without click on the button :

[code]

Time: [/code]

Don’t try to declare your functions outside of a namespace. Your code “runs” in a way that’s sandboxed, so those function declarations will just go out of scope and disappear.

First of all, you should be using your own namespace. Once you have that, you’d declare your functions something like this:

XojoCustom.acme.clock.start = function() {

Wait what? It does? Where? How? I’m interested :smiley:

Michel run into an issue with using WebHTMLViewer it works fine using loadpage in the open event or if I put a button on the form that does htmlViewer1.loadpage(clock)

However

If I try and push scoreboardpages(i).htmlViewer1.loadpage(clock) it blanks the iframe

For i As Integer = 0 To uBound(ScoreboardPages) scoreboardpages(i).htmlViewer1.loadpage(clock) Next i

Push works fine for everything else like changing the values on labels etc, the below does work

For i As Integer = 0 To uBound(ScoreboardPages) scoreboardpages(i).label.text = "HELLO" Next i

any ideas?

It does indeed. Will compose a demo app with comments in the morning for you to demonstrate pushing data to client-browsers. :slight_smile:

I think the example ‘HelpDeskWithChat’ demonstrates this? Sends messages directly to other specific sessions.

[quote=118211:@Graham Spratt]Michel run into an issue with using WebHTMLViewer it works fine using loadpage in the open event or if I put a button on the form that does htmlViewer1.loadpage(clock)

However

If I try and push scoreboardpages(i).htmlViewer1.loadpage(clock) it blanks the iframe

For i As Integer = 0 To uBound(ScoreboardPages) scoreboardpages(i).htmlViewer1.loadpage(clock) Next i

Push works fine for everything else like changing the values on labels etc, the below does work

For i As Integer = 0 To uBound(ScoreboardPages) scoreboardpages(i).label.text = "HELLO" Next i

any ideas?[/quote]

Forgive my curiosity, but why would you want to load the same page in the HTMLViewer repeatedly like that ?

Because I need to reset it for each new race

Would not scoreboardpages(i) be instances of a single WebContainer ?