Digital Workshop

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Script Action on button.
PostPosted: January 1st, 2018, 4:02 pm 
Offline

Joined: June 26th, 2007, 11:59 am
Posts: 60
Opus: Opus 9.01
OS: Windows 7
System: Heinz 57
I have created a script object on a page in an html5 publication which is triggered by a script action on a button.

This works works well within the Opus editor however when I publish it the action in the object does not initiate when the button is clicked on. The script action is used to shuffle the contents of an array. Can anyone tell me why this fails when published but is OK within Opus?

Test publication is attached:

Dave


You do not have the required permissions to view the files attached to this post.

_________________
Opus Pro v7, Windows XP Pro SP2, Intel Core 2 , Quad CPU Q6600 @ 2.4GHz, 1GB RAM, Partitioned HD 10 GB & 30 GB. Internet Explorer 7.


For this message DaveB56 has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Script Action on button.
PostPosted: January 10th, 2018, 12:52 pm 
Offline

Joined: June 26th, 2007, 11:59 am
Posts: 60
Opus: Opus 9.01
OS: Windows 7
System: Heinz 57
Still no response from anyone and I am bashing my head against the wall!

On the button to go to the first question I have this action: "GotoPage(questionbank[0])"

This works in the Opus editor but not when published. I guess something is wrong in the page Opus Script object?

That reads:

//name all the elements after the pages
questionbank[ 0 ] = "Q1";
questionbank[ 1 ] = "Q2";
questionbank[2] = "Q3";
questionbank[3] = "Q4"
questionbank[4] = "Q5"
questionbank[5] = "Q6"
questionbank[6] = "Q7"
questionbank[7] = "Q8"
questionbank[8] = "Q9"
questionbank[9] = "Q10"
questionbank[10] = "Q11"
questionbank[11] = "Q12"
questionbank[12] = "Q13"
questionbank[13] = "Q14"
questionbank[14] = "Q15"
questionbank[15] = "Q16"
questionbank[16] = "Q17"
questionbank[17] = "Q18"
questionbank[18] = "Q19"
questionbank[19] = "Q20"
questionbank[20] = "Q21"
questionbank[21] = "Q22"
questionbank[22] = "Q23"

shuffle(questionbank);

//Shuffle the array elements
function shuffle(array) {
var m = array.length, t, i;

// While there remain elements to shuffle…
while (m) {

// Pick a remaining element…
i = Math.floor(Math.random() * m--);

// And swap it with the current element.
t = array[m];
array[m] = array[i];
array[i] = t;
}

return array;
}


I guess I am not calling the button script action correctly from the page script object?

If anyone can help it would be most appreciated.

_________________
Opus Pro v7, Windows XP Pro SP2, Intel Core 2 , Quad CPU Q6600 @ 2.4GHz, 1GB RAM, Partitioned HD 10 GB & 30 GB. Internet Explorer 7.


For this message DaveB56 has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Script Action on button.
PostPosted: January 10th, 2018, 4:46 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Function is fine. You need to use a different naming format for the pages.

Anything with a letter on at the end should be fine. Such as P1D.

</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: Script Action on button.
PostPosted: January 10th, 2018, 6:20 pm 
Offline

Joined: June 26th, 2007, 11:59 am
Posts: 60
Opus: Opus 9.01
OS: Windows 7
System: Heinz 57
Thanks Mack, change it to something like "1Q" and "2Q" etc. Why would that be, I've obviously missed something in the tutorials/help?

_________________
Opus Pro v7, Windows XP Pro SP2, Intel Core 2 , Quad CPU Q6600 @ 2.4GHz, 1GB RAM, Partitioned HD 10 GB & 30 GB. Internet Explorer 7.


For this message DaveB56 has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Script Action on button.
PostPosted: January 10th, 2018, 9:22 pm 
Offline

Joined: June 26th, 2007, 11:59 am
Posts: 60
Opus: Opus 9.01
OS: Windows 7
System: Heinz 57
Hi Mack, I have made the changes to the page number names as suggested and the "Go to" action on the button does now work when published. However, the shuffle(array) function in the page script object will not now work when published.

I have added another button to test the "shuffle" action and attached a test pub.

Help would be appreciated.

Unfortunately there is a message "Sorry, the board attachment quota has been reached".

_________________
Opus Pro v7, Windows XP Pro SP2, Intel Core 2 , Quad CPU Q6600 @ 2.4GHz, 1GB RAM, Partitioned HD 10 GB & 30 GB. Internet Explorer 7.


For this message DaveB56 has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Script Action on button.
PostPosted: January 10th, 2018, 9:34 pm 
Offline

Joined: June 26th, 2007, 11:59 am
Posts: 60
Opus: Opus 9.01
OS: Windows 7
System: Heinz 57
Now resolved Mack. I had accidentally dropped the line "questionbank = new Array();" in the page script object!

_________________
Opus Pro v7, Windows XP Pro SP2, Intel Core 2 , Quad CPU Q6600 @ 2.4GHz, 1GB RAM, Partitioned HD 10 GB & 30 GB. Internet Explorer 7.


For this message DaveB56 has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Script Action on button.
PostPosted: January 11th, 2018, 9:42 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Glad it works.

I don't think you'll find it in the help, though I'm sure I've discussed it before but that might be in the evolution section - so here's a reminder:

1. The naming of pages in the HTML5 output is not necessary the name you used in the Opus IDE. I believe this is to avoid conflicts and handle non safe URL characters. My philosophy is to try and name based on a unique description with the object type at the end using camel-case with no non-alphanumeric characters - such as quizQuestionOnePage. This hopefully avoids duplication of names, URL naming conflicts, easily identify what object I'm working with should I need it use it when coding and to help my clients implement work I've built for them.

You don't actually need to do this if not using code - but personally, I think it's good practice.

2. The reason the code fails without defining the array line, although it's a publication variable and works in Opus, is because Opus HTML5 uses Objects in place of an Array, In JavaScript, Arrays are technically Objects, but when you use a numbered index array, it is possible to manipulate the Array in ways that will silently fail if used on an Object - the shuffle function is an example of this happening.

The solution is to either rewrite the shuffle function to handle an Object and treat the variable as an Object at all times or simply make use of JavaScript's loose typing and treat the Object (as created by Opus) as a Number Indexed Array (as defined by us).

</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  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 33 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group