Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 12:53 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Game Scoring HTML5
PostPosted: September 1st, 2017, 6:58 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
I need to add scoring to an Opus published HTML5 game (JS in an external JS file), and want to pass the incremented score (score++) back to the Opus page, for example to a text box with the score variable inserted.

If I add an incrementing score counter (counter1 +=1 or counter1++) to the external JS when a successful scoring action occurs, (1) how do I pass this from the external JS file and (2) how do I refer to the score variable in Opus Script?

Best Wishes,

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Game Scoring HTML5
PostPosted: September 3rd, 2017, 10:41 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Publication variables are properties of the _DWPub object but if you are wanting an on-screen variable to update then in may be better to call a function on the Opus page from the external JS as this will trigger the code Opus uses to update on-screen elements.

Code:
_DWPub.m_currentPage.myOpusFunction(value)

</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


For this message mackavi has been thanked by : Stephen


Top
 Profile Visit website  
 
 Post subject: Re: Game Scoring HTML5
PostPosted: September 3rd, 2017, 3:54 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi Mack,

Thank you for this.

So far, 'molasses for brains' this morning, for me. :lol: Can't figure this out. Trying to add a scoring function to Bejeweled. js based on number of new gems placed (probably a good indicator of successful matches). If 3 gems placed, score 3, if 4 gems, 4, etc.

There is a local function in Bejeweled.js that seems to record how many gems are placed after a turn:

Code:
function placeNewGems(){


In this function, there is a variable: gemsPlaced.

So, if I create a score-counter text box on the Opus page with a variable: counter inserted, then in the external Bejeweled.js script, add _DWPub.counter=gemsPlaced (placed somewhere in the external script, but not sure about where or what event handler to use/add?), maybe this would work to keep and display score? Have tried any number of combinations based on this, reading up on global scoped variables, etc. but after many hours of trying, no joy.

Any suggestions would be much appreciated.

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Last edited by Stephen on September 3rd, 2017, 5:47 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Game Scoring HTML5
PostPosted: September 3rd, 2017, 5:36 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
First, to find the variable that you're looking for using console.log(variable name) and display the debug tools for your browser.

Once, you've got that you'd better trying the second method I suggest as simply changing the Opus variable may not be reflected on screen. So for example,

Code:
_DWPub.m_currentPage.setScore(gemsPlaced)


Will call a function called setScore (you have to create this) on the current Opus page and pass your gemsPlaced variable. Again you can use window.console.log to check that it has been passed to Opus. It'll look something like:

Code:
function setScore(variable_from_external_script){
on_screen_variable = variable_from_external_script; 
}


</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Game Scoring HTML5
PostPosted: September 3rd, 2017, 5:48 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Thanks, again.

Making progress.

If I add a variable (counterG) to the external script, pair it as counterG++ in the same function as gemsPlaced++, equate it to the screen variable (counter=window.counterG), in a 1-second ticker trigger, when I test and make a correct match, it will increment by +1 and successfully display. Additional matches are added and correctly displayed on screen.

Would prefer to update simply by using a variable-changed trigger instead of a 1-second ticker, but so far hasn't worked. counter=window.counterG has to be triggered in order to change the variable and utilize the variable-changed trigger. The variable changed trigger won't accept a window.counterG (or window.gemsPlaced) variable using this window. syntax. So, not sure how to improve upon using ticker every second? Maybe, I'm not yet fully understanding this?

Can also rotate the F1 frame but only in 360 degree + or - amounts. If the angle rotated is less or more than 360, gem selection is off.

Any suggestions appreciated.

Best Wishes,

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 34 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group