Digital Workshop

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Hints in a Hidden object game
PostPosted: August 21st, 2011, 4:48 pm 
Offline

Joined: July 20th, 2011, 8:58 pm
Posts: 4
Hi Everybody,

I am new to Opus and is in the process of coding a Hidden Object game. The idea is that names of objects are listed in a window at the bottom of the page (10 objects) and the player must then find these objects and click on each to have it removed from the list. I have all of that working fine. To get a hind, a flag is clicked which fires a canon and the canon ball would then drop from above and explode on the object. My problem:
1. How do I get the tween to move to one object that has not been found?
2. How do I control the distance the canon ball must drop to land on the object?

With the following code I can control the X-axis movement but the Y-axis movement does not work. I have also hard coded the name of the object to find.( Pistol)

var destXY = Pistol.GetPosition(10);
Explode.SetPosition(destXY.x,destXY.y);
Explode.Show();
Explode.GotoAndPlay(1);
Explode_2.SetPosition(destXY.x,destXY.y);
Explode_2.Show();
Explode_2.GotoAndPlay(1);
Explode.GotoFrame(0)
Explode_2.GotoFrame(0)

Explode is the tween for the canon ball dropping and explode_2 for the explosion once it hits the object.

Any help will be highly appreciated.


Top
 Profile  
 
 Post subject: Re: Hints in a Hidden object game
PostPosted: August 22nd, 2011, 12:20 am 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Dirk,
welcome to Opus and the opus forum.

Your 2nd question:
Quote:
2. How do I control the distance the canon ball must drop to land on the object?
If you are making a 'ballistic' arc, an easy way to approach this is to create 10 Path Objects, each from same starting point but the arc/trajectory ending at different objects. The question becomes then, 'how to trigger' one of the different 10 paths' (which is related to your first question anyway :twisted: )

BTW, check out 'gravity' or 'bouncing ball' in the Tutorial section of the Forum: one example:
Bouncing Ball - Part 1: Simulating gravity and bounce at: viewtopic.php?f=13&t=315
Bouncing Ball - Part 2: Horizontal motion, walls and ceiling
Bouncing Ball - Part 3: Allowing user control of the ball
and others

Also, for your 2nd question, re: "distance" dropped: In Opus, you can use a Standard Trigger for determining the 'detonation' point. Look for Trigger "Collision Entered". Then (I would) set up a Standard Action to execute a script (look under Programming Tab there... for Script Action). I think this is your explode2 set. FYI, if you want to stay with OpusScript for this, the command is ObjectA.IsIntersecting( ObjectB) -- which will return true or false. You probably want a Loop to test repeated "while" cannon ball is in motion.

Quote:
My problem: 1. How do I get the tween to move to one object that has not been found?
One way is to have a variable associated with each Object being hunted -- and when 'found', change the flag variable to true, or 1, or whatever. Then as User progresses, you can test your list of Objects to find one that has a flag value of false, or 0, or something. This will give you explicit control.

A simpler method is simply to test your list of 'hunted objects' for whether it is hidden or not. e.g., Tree1.IsShowing() will either be true or false. (can use this method if you leave 'found' objects visible.)

for this specific part
Quote:
get the tween to move to one object
I am not clear on your layout and plan, is Pistol one of the objects in the hunt? If so, you seem to have a solution for 'movement'.

Maybe your question is rather 'assignment' or 'selection'? Let me know.
In that case, you could read this: (from... viewtopic.php?f=4&t=3222&hilit=this+pass+object+function&start=45 )
Quote:
Just a smaller pointer to keep things simpler - if working on an actual object passed to a function you can pass the object NOT the name IE:

theRotateFunction(this) rather than the RotateFunction(this.GetName())


It eliminates the need for the eval function which is better suited to executing sequential processing such as a group of objects named V1..V10.

Passing the object allows you to treat the object as an object in your function directly:

function theRotateFunction(thingy)
{
thingy.Rotate(45)
}



Basically, you call a function once you know which next Object you want the tween to operate on. Look at some prior discussions... about using the KEYWORD this -- for flexibility and for passing or accepting different objects in a function. Good stuff here (further down / Mackavi):
viewtopic.php?f=11&t=3111&hilit=this+object+function

Cheers,

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject: Re: Hints in a Hidden object game
PostPosted: August 28th, 2011, 6:51 am 
Offline

Joined: July 20th, 2011, 8:58 pm
Posts: 4
Hi Lar,
Thanks for the information you supplied. I played some more with this but ran into a brick wall.

The problem is that there are 10 possible objects, some of which could already have been found by the player. One now have to test if the object is still available and if it is, move to the next objects position and play the tween.

I now get the movement right and the tween is playing. I do however still have two problems.

In the script below, name1 is one of the variables that are reset to 0 if the object is no longer available. To test for all ten objects, I repeat the same script 10 times with the variable changing to name2, name3, etc. The position to find also changes accordingly.

//Test if object is still available and if yes, play tween//
if (name1!=0)
//Find position of available object//
{var destXY = HintShow[1].GetPosition(10);
//Move in line with object and play tween//
Explode.SetPosition(destXY.x,destXY.y);
Explode.GotoAndPlay(1);
Explode_2.SetPosition(destXY.x,destXY.y);
Explode_2.GotoAndPlay(1);
Explode.GotoFrame(0);
Explode_2.GotoFrame(0);

}
//Repeat ten times//
if (name2!=0)
{
var destXY = HintShow[2].GetPosition(10);
Explode.SetPosition(destXY.x,destXY.y);
Explode.GotoAndPlay(1);
Explode_2.SetPosition(destXY.x,destXY.y);
Explode_2.GotoAndPlay(1);
Explode.GotoFrame(0);
Explode_2.GotoFrame(0);
}

Now my problem. If I enter just the first if statement, it works perfectly and the correct object is indicated. When I add the second and more if statements, the tween plays at a random object that is not listed as one of the possible 10 objects. Subsequent requests for a hint repeats the playing of the tween at the same position as previously. If I restart the preview, it would play at a different position as previously.

This confuses me completely. I cannot understand why it would work if I use one if but not if I use more than one.

My second problem is with the OnCollision() statement. If I hard code the object name here, it works fine. How do I get it to react to a variable? Whenever I use a variable as the object, nothing happens, as if the script is not executed.

Your help will be highly appreciated as this is frustrating me.


Top
 Profile  
 
 Post subject: Re: Hints in a Hidden object game
PostPosted: August 28th, 2011, 8:29 am 
Offline

Joined: October 25th, 2004, 3:03 pm
Posts: 540
Location: Tyalgum Creek. Australia
Opus: Opus Pro Latest version 9.02 Build 16458
OS: Won 10
System: Asus laptop Intel Core i5 8 gig ram, big monitor, reading glasses
Not sure if this helps
Have you considered giving each object a numerical value say 1?
You have 10 objects that can be found in any order.
After all 10 are found the cannon fires? Yes
Therefore if my logic is correct, you need to add 1 to a variable and then a test that says If var cannon =10 fire the cannon.
So at the beginning the variable cannon is set to 0 and as obects are discovered 1 is added and the test if var = 10 fire cannon is run.
Hopefully this helps
Cheers
Graham

_________________
Too much coffee can result in frequent toilet breaks!


Top
 Profile  
 
 Post subject: Re: Hints in a Hidden object game
PostPosted: August 28th, 2011, 9:57 am 
Offline

Joined: July 20th, 2011, 8:58 pm
Posts: 4
Hi Graham,

No, the canon fires if the player hits the hint button. The canon ball then explode on one of the objects to be found, giving the hint as to where the object is. I must thus test if the object has been found or not. If not, the canon ball drops over one of the items that are still in the list of objects to find.

I have a variable the holds the name of the object to be found. If the object is clicked on, the object and the name is hidden. The variable then change to zero. So for the hints, I test to see if the name is 0, if not, then the object is selected to show the hint. This is where the problem comes in with the "if" statements as explained in my previous post.


Top
 Profile  
 
 Post subject: Re: Hints in a Hidden object game
PostPosted: August 29th, 2011, 11:49 pm 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Dirk,

Be sure to NOT name variables and objects with the same name. I cannot tell if you are doing that, but you mentioned 'name1' as a var.

Try this:

ONE -- Create a Script Object on your Page and copy the following script into it. YOU will have to finish the coding for the ten items.
Code:
function lookupVariable( OBJparm )
{
//I avoid 'simpler methods' here, because I don't want to explain Arrays or assigning object PROPERTIES. So this is brute force method.
//activeVariable   --- should be set up as a Page variable (or declared earlier in script as a Global variable)
switch (OBJparm.GetName())
{
case "Article01":
activeVariable = name1 ;
return;

case "Article02":
activeVariable = name2 ;
return;

case "Article03":
activeVariable = name3 ;
return;

// You need tomake ALL TEN object and variable matches -- i.e., finish the coding

case "Article10":
activeVariable = name10 ;
return;

default:
activeVariable = undefined ;
return;
}

} //end function

function Check_User_Guess( whichObject )
{
//Let's do a lookup to get value from appropriate variable corresponding to selected Object
lookupVariable( whichObject )

//your values of 0 or 1 whoulc be pulled in for the appropriate variable, name2 etc
     if ( activeVariable != undefined )
     {
     var appliedVariable = activeVariable ;
     }

   if (appliedVariable !=0)
   {
   //Note:  when you called the function with argument of HintShow[2],  this function uses that Object (or variable if it were a variable) with the 'handle' of:  whichObject
   var destXY = whichObject.GetPosition(10);
   Explode.SetPosition(destXY.x,destXY.y);
   Explode.GotoAndPlay(1);
   Explode_2.SetPosition(destXY.x,destXY.y);
   Explode_2.GotoAndPlay(1);
   Explode.GotoFrame(0);
   Explode_2.GotoFrame(0);
   }
   else
   {
   //do something here to tell the User he needs to choose another object    OR use the following
   }
} //end function



TWO
Whenever the User makes a choice or guess, call the following function
This assumes HintShow[2] is an Object.

Code:
Check_User_Guess( HintShow[2] )



Hope that works.

Even after reading your posts several times, I am sure I am not clear on all the intended flow... nor the naming. So like your Users, I am "guessing" :?
For example, IF I knew your naming of the articles, it might be simpler to use a FOR LOOP and some concatenation of names. Oh well.

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject: Re: Hints in a Hidden object game
PostPosted: August 30th, 2011, 5:32 am 
Offline

Joined: July 20th, 2011, 8:58 pm
Posts: 4
Hi Lar,

Let me explain the process a bit further for clarity.

There are 65 different graphical objects on a background image. These objects are the objects the player should find. At the bottom of the screen is a box where 10 object names are listed in capital letters. I have entered all these names into an array and use a random number generator to select 10 random names from the list. The graphical objects have similar names but in lower case letters. Also, where the displayed name consist of two or more words, the object name words are combined with _.

The object of the game is to find the listed 10 objects, one of which would be an object that is required to move to the next stage of the game. This object is hard coded into the list of objects to find and is thus excluded from the random objects. This is to make sure that it is available each time the game is played. When a player clicks (or finds) an object, he would click on it and both the object and the displayed name would be hidden and a tween and a sound would play.

This I have all got working.

My problem starts when the player is stuck and cannot find an object. To activate the hint, he would click on a flag next to a canon. The canon would fire with a tween playing which shows smoke coming from the barrel and sound and the flag would drop and slowly rise again. This is a time delay to prevent the player from hitting one hint immidiately after the other. All this work fine without any problems.

The canon ball is positioned at the top of the screen (just off screen). When a hint is requested, it is suppose the check which of the objects has still not been found, move to over this position and fall (become visible and play tween). Once it gets to the object, it is hidden and another tween plays creating a larger smoke object. The tween plays itself out and is hidden.

Again, this works fine if I hard code the object name into the hint button. The names of the objects to be found (displayed at the bottom of the screen) is stored in variables name1 to name10. If the object is found, I change this varaible to 0 and test for this in the hint code.

Now this is where my ten "if" statements come in. I check each "nameX" to see if it is 0 or not. If not, move the canon ball to the x-axis of the object and play the tween.

If I only test for one object (name1) (one "if" statement) it works fine and the right object is indicated. If the object is removed, it does nothing, which is also correct. If I add the second "if" statement, it sometimes work well and at another fails. If I add all ten, it ignores everything and move to a random object that is not in any of the name variables. It then plays the tween over this object. It then also makes this object clickable although it is not in the selectable object list. If you click on this object, it is hidden but the tween keeps on playing over that position every time you click on the hint button and do not move to a new position.

What I cannot understand is why does one if statement work but more does not.

I have also placed the names of the objects in an array and when the 10 random objects are generated, I simultaniously put the corresponding 10 object names into an array called "HintShow[X]" This could be the cause of my problem but my programming skills does not allow me to do it in any other way.

Hopefully this long essay would help you in better understanding my problem. I tried your solution but get exactly the same result.

Thanks for trying to help me.


Top
 Profile  
 
 Post subject: Re: Hints in a Hidden object game
PostPosted: August 30th, 2011, 8:09 am 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Quote:
What I cannot understand is why does one if statement work but more does not.
I have also placed the names of the objects in an array and when the 10 random objects are generated, I simultaniously put the corresponding 10 object names into an array called "HintShow[X]" This could be the cause of my problem but my programming skills does not allow me to do it in any other way.
Have you tried debugging using Debug.trace() ?
You need to check the flow of your logic --- both for the IF statements as well as monitoring the match-up of Objects and related variables.
(BTW, Opus' debug pane also has a Tab for 'variable watch')

Thanks for a more complete explanation. Maybe others can see something rather obvious which I fail to see.
...I do not have time now to try to digest your work and recreate it from scratch.

You might try to post a simplified example, .imp file -- and likely someone can spot the breakdown.

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject: Re: Hints in a Hidden object game
PostPosted: September 27th, 2011, 2:36 pm 
Offline

Joined: May 24th, 2007, 11:02 am
Posts: 132
Location: UK - Wales - Ceredigion
Opus: illuminatus > Evolution
OS: Windows 10 Pro
System: i7 8GB RAM
It would be helpful if you could post a sample so we can help.
I have a few ideas, but would like an example of what you're trying to achieve.

If you got it working - how did you do it?


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

All times are UTC [ DST ]


Who is online

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