Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently May 18th, 2024, 12:09 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: HTML5: Question about how to use "move" with variables ...
PostPosted: May 2nd, 2016, 3:25 pm 
Offline

Joined: November 8th, 2004, 5:23 pm
Posts: 279
Opus: Opus Pro 9
OS: Win 10/64
Hi, I would like to move some image objects via script commands.

That works fine as long as I use the real image object names:

Code:
ball.MoveY(50, 2.0)


What I want to do is using a variable instead of the real name of every single image object.
So I tried this in various ways, which are obviously wrong:

Code:
myobjectname = "ball"
(myobjectname).MoveY(50, 2.0)

or

myobjectname.MoveY(50, 2.0)



Instead of moving the object "ball" I get an error message instead.

I think the reason for this could be that the move-function does not know or recognize that the variable myobjectname is an image object.
Unfortunately I have no idea how to achieve the desired result.

I hope someone can show me how to do this right.

Thanks :)

_________________
Opus Pro 9.75, Win 10/64, 8 GB RAM, Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz (4 CPUs), ~3.4GHz, NVIDIA GeForce GTX 660 Ti, Roland OctaCapture


For this message Tarantoga has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: Re: HTML5: Question about how to use "move" with variables .
PostPosted: May 3rd, 2016, 9:13 am 
Offline

Joined: November 8th, 2004, 5:23 pm
Posts: 279
Opus: Opus Pro 9
OS: Win 10/64
I think I found a solution by myself.

You have to use "eval" to achieve this:

Code:
var ObjName = objectname
var NextTask = "Move(20,30,0.5)"
var perform = ObjName +"." + NextTask
eval(perform)


In this way it works as it should.

Although I am glad that it works now, I am interested in WHY this is so.
I have to admit that I do not really understand what "eval" does.

Maybe someone of the experts can explain this in simple words? That would be great!

_________________
Opus Pro 9.75, Win 10/64, 8 GB RAM, Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz (4 CPUs), ~3.4GHz, NVIDIA GeForce GTX 660 Ti, Roland OctaCapture


For this message Tarantoga has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: Re: HTML5: Question about how to use "move" with variables .
PostPosted: May 3rd, 2016, 9:35 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Eval is short for evaluation and basically attempts to 'run' the string within the brackets as if it were code.

In your first post - the "ball" in inverted commas, is simply a string and means nothing more to Opus than "apples", "oranges" or "pears".

ball.move(x,y) however references an object not a string. In this case, the object is an on screen object such as an image, vector or frame.

In order, for a variable to work with move(x,y), the variable needs to reference an object. Opus includes different ways of achieving this, including FindChild(). You can also use the 'this' keyword for example:

Add the following line to an on show trigger on the ball image:

Code:
myVariable = this

As you have discovered, eval works, but it is not necessary the safest or best way to acquire an object. Understanding that objects are probably the most important aspect of Opus and definitely HTML5 programming will help you build better applications and you'll find I've posted quite in depth responses before on the topic.

</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: HTML5: Question about how to use "move" with variables .
PostPosted: May 3rd, 2016, 9:47 am 
Offline

Joined: November 8th, 2004, 5:23 pm
Posts: 279
Opus: Opus Pro 9
OS: Win 10/64
Mack, thank you very much for your help and the explanation.

With your help I could solve the problem without using eval().
I think it works even faster this way :D

Great support!

_________________
Opus Pro 9.75, Win 10/64, 8 GB RAM, Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz (4 CPUs), ~3.4GHz, NVIDIA GeForce GTX 660 Ti, Roland OctaCapture


For this message Tarantoga has been thanked by : mackavi


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

All times are UTC [ DST ]


Who is online

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