Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 11:27 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Scripting Array
PostPosted: February 4th, 2014, 2:56 am 
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
Same puzzle pub for Opus Pro 9.

To save on using multiple standard actions, in this case rotating back to 0 angle each of 36 puzzle pieces (F1-F36) so they are essentially reset.

How to script an array for F1-F36 and set each's display data angle to 0? Currently using 36 standard actions. Since several buttons with these 36 standard actions, pub becoming slow.

Tried the following based on previous example by Mack, but this time, couldn't get it to work for this rotation:

Code:
function chooser200(len2, sub2)
{
   var a  =new Array;
      for (var i=0;i<len2;i++) //generate numbers
      a[i] = i+1
      eval("F"+a[i] +".SetRotation(0,true,1.0)")

}

//chooser200(36,36)


So, I must be doing something wrong.

Again, must be a more efficient (and correct) way to do this using script.

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Scripting Array
PostPosted: February 4th, 2014, 9:43 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Code:
function doReset(len) {
   for (var i=1;i<=len;i++)
      eval("F"+i+".SetRotation(0,0,0,0)");

}



FYI: Given the bigger picture, it would be better to use OOP rather than eval() all the time. This would involve assigning the host objects (IE Frames) to a variable or array element - and allow them to be manipulated directly. The attached example shows how to do that - and you can then apply the same for loops for randomising / reset directly on the object rather than having to resort to eval.

FYI2: Eval doesn't have a great reputation. It's one of those commands, that is best used with a pinch of salt and with an understanding that there is normally, a better, if not more advanced solution to solve the problem.

Mack


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

_________________
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: Scripting Array
PostPosted: February 4th, 2014, 2:06 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
Thank you, Mack.

Yes, avoiding overuse of the eval function is a good idea.

So, this substitute works:

Code:
function doReset(len) {
var pieces10 = new Array(F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F20,F21,F22,F23,F24,F25,F26,F27,F28,F29,F30,F31,F32,F33,F34,F35,F36);
   for (var i = 0;i < len;i++)
      pieces10[i].SetRotation(0,0,0,0);
}

_________________
Stephen


For this message Stephen has been thanked by : mackavi


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 24 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