Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently January 8th, 2025, 8:59 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Problem with nested ifs.
PostPosted: November 26th, 2004, 10:56 am 
Offline

Joined: November 3rd, 2004, 2:35 pm
Posts: 117
Location: Swansea, South Wales
Trying to create a simple matching game with two variables to keep score.

<total> holds the number of objects sorted
<correct> holds the number sorted correctly.

I'm using a Variable Changed Trigger on the page to tell when all the objects have been sorted. i.e when total=3 in this case.

I then want to display one of two messages based on the value of total and am using a nested if so that the logic looks sometihng like:

Quote:
Variable Changed <total>
If total=3
If correct = 3
Show Well done
Else
Show Try Again


Only it doesn't work. it Always shows the "again" message.

It does work though if I attached the "If correct" action to a button instead of nesting it within the "If total" attached to variable changed.

Is my logic faulty somewhere? I have another publication using Variable Changed and nested Ifs in this way.

Problem publication attached.


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


Top
 Profile Visit website  
 
 Post subject:
PostPosted: November 26th, 2004, 11:56 am 
Offline

Joined: October 25th, 2004, 12:27 pm
Posts: 526
Location: Digital Workshop
Hi,

Thank you for your enquiry.

The problem is that Opus is processing the This Object Dropped triggers on the coloured shapes before it processes the Object Dropped triggers on the drop zones. The <total> variable is therefore being updated a fraction of a second before the <correct> variable, so when <total> reaches 3, the Variable Changed trigger checks the current value of <correct>, sees that it is still set to 2 (as the update has not yet taken place) and displays the 'Try Again?' message.

There are various solutions, including adding a small delay (0.01 seconds) to the start of the Variable Changed actions, but the most elegant workaround would be to remove the This Object Dropped from the coloured shapes and apply Object Dropped All Objects triggers to the drop zones to increase the <total> variable.

I have attached a modified version of the publication to demonstrate this.

Kind regards,


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

_________________
Robin Garrett
Digital Workshop Technical Support


Top
 Profile Visit website  
 
 Post subject:
PostPosted: November 26th, 2004, 12:02 pm 
Offline

Joined: November 3rd, 2004, 2:35 pm
Posts: 117
Location: Swansea, South Wales
Ah Bingo! I thought I was going barking.

I must have just been lucky with the timing on on the other one.

Are these little 'gotcha's something that come with experience or is their any info out there as to which actions are processed first?


Top
 Profile Visit website  
 
 Post subject:
PostPosted: November 26th, 2004, 1:41 pm 
Offline

Joined: October 25th, 2004, 12:27 pm
Posts: 526
Location: Digital Workshop
leiafee wrote:
Are these little 'gotcha's something that come with experience or is their any info out there as to which actions are processed first?


When updating multiple variables at the same time, it is a good idea to try and isolate the variable actions to as few objects as possible, so that you have a much better indication of which updates are taking place in which order.

For example, in your problem publication, dropping a shape name onto the correct shape caused the name object to increase the <total> variable and the drop zone to increase the <correct> variable. However, unless you implement delays, you have no way of knowing which action is processed first (it happens to be the action on the text object, but I could only tell you this based on the behaviour of the problem publication).

However, if both actions are assigned to the same object, you can be sure that the top-most action will be processed first, followed by the next action in the list and this should eliminate any possibility of Variable Changed triggers interrogating variables before they have correctly updated.

Hooray...it's my 100th post!
Image

I hope this helps. Please do not hesitate to contact me if you have any further queries.

Kind regards,

_________________
Robin Garrett
Digital Workshop Technical Support


Top
 Profile Visit website  
 
 Post subject: Hundredth Post
PostPosted: November 27th, 2004, 5:17 am 
Offline

Joined: October 26th, 2004, 1:26 pm
Posts: 262
Congratulations Robin on your 100th post. :!:

I must say, all your posts are consistent and even! :lol:

_________________
Cheers,
Steve


Top
 Profile  
 
 Post subject:
PostPosted: November 27th, 2004, 10:23 am 
Offline

Joined: November 3rd, 2004, 4:28 pm
Posts: 119
Location: Limousin, France
Ah, but most of Robin's posts have been replies to posts from others, and not self-generated, so that's a bit of a cheat!!

I hasten to add that that is no reason for Robin to cease posting, however...... :wink:

Chris

_________________
Chris Kaley
Win XP Pro SP2, Intel 2.66 GHz Core 2 Quad extreme, 4 Gb RAM, NVidia 8800 GTX, 768Mb RAM, Dual Iiyama TFT
Opus Pro XE v4.5, XE v5.5


Top
 Profile  
 
 Post subject:
PostPosted: November 29th, 2004, 5:57 pm 
Offline

Joined: November 3rd, 2004, 2:35 pm
Posts: 117
Location: Swansea, South Wales
Cheers, Robin. A very useful 1000th post!


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 51 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