Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Danman on Wed 10/03/2010 16:03:25

Title: Minigame Technique help.
Post by: Danman on Wed 10/03/2010 16:03:25
I am making this creepy puzzle, Mini game my sister wanted in her game. That is quite weird but I just think it will make the game unique in a twisted weird way.

The Mini game is that my sister (Lisa, Player) Has to shave this guys chest.. very weird i know.
( And Don't misread that! )  (I know things I do for my sister's games)

What is the best way to do this?
My real problem is I find it hard to script a game that progresses.

So just as a guess I will make like 9x9 Objects. 18 in total

Then If the player uses Shaving cream the Sprite changes. then if the player uses Razor make the Hair or whatever visible = False.

Then

if hair.visible = false
{ player.changes room(1); }

Also how to make it that the room only changes when all the objects are visible=false only.

Sorry I would put the code but I don't have AGS to write it out.

Just really asking if this is the best way. and how does everyone else do Puzzles like that.
( Not that anyone has ever done a puzzle with shaving someones chest but anyway)




Title: Re: Minigame Technique help.
Post by: Mouth for war on Wed 10/03/2010 16:41:43
I'm not a great scripter but for changing the room when all of the hairs are invisible. I guess you could use a variable. And if you have 18 hairobjects. Everytime you shave one piece of hair add 1 to the variable and make 1 hairobject disappear and when the variable is = 18 the room changes to another.
so at the top of the script for that room use int hair =0;  (Or whatever you want to call the variable, hair,shave or whatever) and then in the

room_RepExec

if (hair ==18){
player.ChangeRoom(4, 100, 50);
}
Maybe that could work?
Title: Re: Minigame Technique help.
Post by: Danman on Wed 10/03/2010 16:52:04
Yea I am only just learning Variables

But I keep getting confused.

How do the objects relate to the  variable. 

Do I just tell it to Add 1 to the variable after every hair is removed.
Title: Re: Minigame Technique help.
Post by: Mouth for war on Wed 10/03/2010 17:14:56
In your room. Select the object and use the events (the lightning shaped object)
and "Use inventory on object"
then in the script

if(player.ActiveInventory == irazor){              (or whatever your name for the inventoryitem is)
object[0].Visible = false;  (if your hairobject has the id number of 0 if not change it to the correct idnumber)
hair +=1 ;
}
Title: Re: Minigame Technique help.
Post by: Danman on Wed 10/03/2010 17:25:38
But how will that work with all 18. Do I do
like

if(player.ActiveInventory == irazor){
object[0].Visible = false;
object[1].Visible = false;
object[2].Visible = false;
object[3].Visible = false;
// So on
hair +=1 ;
}


This is just a random guess.

Edit: I just tested this code but with Ikey and one object Id 0. And never removed it
Title: Re: Minigame Technique help.
Post by: barefoot on Wed 10/03/2010 17:26:19
Hi

if you want to do something like go to another room when all objects are invisible
use



if (!oObject4.Visible && !oObject3.Visible && !oObject2.Visible) {


player.ChangeRoom(20);



The above checks if 3 Objects are invisible.... if they are then the next part happens.

Obviously use your Objects' Name and Room Location you want to go to etc

Hope this helps

barefoot

Title: Re: Minigame Technique help.
Post by: barefoot on Wed 10/03/2010 17:34:39
If you want to use an inventory item on an object to change it to another object you will need to make all the inventory items as well.

Something like this:


if (player.ActiveInventory == icream)
    {
      object[1].Visible = false;
      object[2].Visible = true;
   


You obviously need to stack the objects if the are meant to be on top of each other.

so on and so on...

barefoot
Title: Re: Minigame Technique help.
Post by: Danman on Wed 10/03/2010 17:48:44
OK I think I finally got it I have been looking doing this code in the Global script instead of the room script. Sorry  :-[ . Thanks I will practice doing this on the game. Then see where I get stuck Thanks A lot guys  ;D .
Title: Re: Minigame Technique help.
Post by: Danman on Wed 10/03/2010 18:19:00
OK I tested this now and this is what I did



// In room script
// room script file
int hair =0;



function Hair1_UseInv()
{
if(player.ActiveInventory == irazor)
Hair1.Visible = false; 
hair +=1 ;
}

function Hair2_UseInv()
{
if(player.ActiveInventory == irazor)
Hair2.Visible = false; 
hair +=1 ;
}









//Right in Repeat exec
function repeatedly_execute()

if (hair==2)
{
player.Say ("All hair removed");
}


And I am sure that should work. The Hair objects got removed but did not say anything.

IS there anything I did wrong  :-\
Title: Re: Minigame Technique help.
Post by: barefoot on Wed 10/03/2010 18:25:41
adjust to:


if (!oHair1.Visible && !oHair2.Visible) {
player.Say ("All hair removed");


barefoot
Title: Re: Minigame Technique help.
Post by: Khris on Wed 10/03/2010 20:05:26
You can't just put a function called repeatedly_execute in the room script, that'll only work for the global and module scripts.
With rooms, you have to use the event.
Title: Re: Minigame Technique help.
Post by: monkey0506 on Wed 10/03/2010 20:26:25
Which can be named repeatedly_execute but by default is called room_RepExec and must be linked in the same manner as other event handlers or it won't be called (unlike the repeatedly_execute function in non-room scripts).
Title: Re: Minigame Technique help.
Post by: tzachs on Wed 10/03/2010 23:20:42
Another problem in your code is missing brackets, change the use inv functions like this:

function Hair1_UseInv()
{
 if(player.ActiveInventory == irazor)
 {
   Hair1.Visible = false;  
   hair +=1 ;
 }
}

The way you did it the hair variable would increase on every inventory being used on the hair, not just the razor...
Title: Re: Minigame Technique help.
Post by: Danman on Thu 11/03/2010 09:29:40
Sorry I didn't mention it was in the global script. I didn't create it I put it in the repeat function that is already there.

Oh yea forgot the brackets.
Title: Re: Minigame Technique help.
Post by: Khris on Thu 11/03/2010 12:17:57
If it's in the global script, I assume you've created the int "hair" there, too (because otherwise you'd get an error).
The reason why that won't work is that you now have two different hair variables. The room's gets increased when the razor is used, but the global script's version's value will stay 0.

Create the variable using the Global variables pane in the editor tree and remove any "int hair;" lines from your scripts.
Title: Re: Minigame Technique help.
Post by: Danman on Thu 11/03/2010 12:58:00
This was in the room script.



int hair =0;



function Hair1_UseInv()
{
if(player.ActiveInventory == irazor)
Hair1.Visible = false; 
hair +=1 ;
}

function Hair2_UseInv()
{
if(player.ActiveInventory == irazor)
Hair2.Visible = false; 
hair +=1 ;
}



When I put the int Hair in the global script it came with an error. Where do I put it in the global script then??
Well I will mess with it a little later after.
Title: Re: Minigame Technique help.
Post by: Khris on Thu 11/03/2010 13:00:56
Read the last line of my previous post.

It is of course still possible to create global variables using the import/export commands, but for basic types, you can do it in the editor.
Title: Re: Minigame Technique help.
Post by: Danman on Thu 11/03/2010 14:12:46
Oh wow! I never saw that before. OK Cool it is working now. Thanks a lot Khris.

One more question where can I put the code



if (Hair == 2)

{
player.Say ("All hair removed");
}

Title: Re: Minigame Technique help.
Post by: Khris on Thu 11/03/2010 16:38:10
You can leave it inside repeatedly_execute, a better way though is to check each time you turn off a hair object.

function RemoveHair(Object*h) {
  h.Visible = false;
  hair++;
  if (hair == 2) player.Say("All hair removed");
}

function Hair1_UseInv() {
  if (player.ActiveInventory == irazor) RemoveHair(Hair1);
}

function Hair2_UseInv() {
  if(player.ActiveInventory == irazor) RemoveHair(Hair2);
}


Note that there's an even better way to have more hair objects without duplicate code:

Instead of a _UseInv for every hair object, use a single function for all of them.

function Hair_UseInv() {
  Object*o = Object.GetAtScreenXY(mouse.x, mouse.y);   // get hair object under mouse
  if(player.ActiveInventory == irazor) {
    o.Visible = false;
    hair++;
    if (hair == 2) player.Say("All hair removed");
  }
}


Now put "Hair_UseInv" in every hair object's event field for "use inv on object". You also don't need to set their names to Hairx any longer.
Title: Re: Minigame Technique help.
Post by: Danman on Sat 13/03/2010 12:19:57
I got an issue with doing my mini game it was working the other day but now I am getting a problem
When i first click on any hair 9x9 with the razor. It changes the room.

I added the empty brackets later just as a test.

here is the Code.


function RemoveHair(Object*h) {
 
   Wait(40);
  h.Visible = false;
  if (Hair <9)
{
  Hair ++;
}


  if (Hair == 2) player.Say("This is a Span of hair");
  {
    }
    if (Hair == 4) player.Say("it is mull");
    {
      }
      if (Hair == 6) player.Say("Seriously is this own a monkey yo!!");
      {
        }
       if (Hair == 9) player.Say("Ok All gone");
       
       {
         player.ChangeRoom(8);
       }
     
}

function hair1_UseInv()
{
if(player.ActiveInventory == Irazor) RemoveHair(Hair1) ;
{


}
}

function Hair2_UseInv()
{
if(player.ActiveInventory == Irazor) RemoveHair(Hair2);
{


}
}

function hair3_UseInv()
{
  if (player.ActiveInventory == Irazor)RemoveHair(hair3);

Hair += 1;
}

function hair4_UseInv()
{
  if (player.ActiveInventory == Irazor)RemoveHair(hair4);

}

function hair5_UseInv()
{
  if (player.ActiveInventory == Irazor)RemoveHair(hair5);

}

function hair6_UseInv()
{
  if (player.ActiveInventory == Irazor)RemoveHair(hair6);
  if (hair6.Visible == false)Display("Ohh a six pack");
 


}



function hair7_UseInv()
{
  if (player.ActiveInventory == Irazor)RemoveHair(hair7);
}

function Hair8_UseInv()
{
  if (player.ActiveInventory == Irazor)RemoveHair(Hair8);
}

function Hair9_UseInv()
{
  if (player.ActiveInventory == Irazor)RemoveHair(Hair9);
}



I cant see why it is changing the room  ???
Title: Re: Minigame Technique help.
Post by: monkey0506 on Sat 13/03/2010 13:56:17
Because, your braces aren't doing anything. Your code following the conditionals is not included in the braces. What you have written is essentially the same as:

if (Hair == 9) player.Say("Ok All gone");
player.ChangeRoom(8);


Meaning of course that only the Say command is being considered as a conditional command and the ChangeRoom command will be executed every single time that the RemoveHair function is called.

You've already been advised previously as to how these braces work, but I'll reiterate it here:
if (Hair == 9) {
  player.Say("Ok All gone");

  player.ChangeRoom(8);
}
As you can see the lines in red have been reversed from the way you typed them. This is the correct way to enclose multiple commands following a conditional.
Title: Re: Minigame Technique help.
Post by: Khris on Sat 13/03/2010 13:59:50
You need to get your if stuff straight.
Look at that piece of code:

  if (Hair == 9) player.Say("Ok All gone");
       
  {
    player.ChangeRoom(8);
  }


The condition check will only affect the execution of the player.Say line.
The curly brackets around the ChangeRoom command don't have any effect at all.

It's supposed to look like this:

  if (Hair == 9)
  {
    player.Say("Ok All gone");
    player.ChangeRoom(8);
  }


Edit: What monkey said :)
Title: Re: Minigame Technique help.
Post by: Danman on Sat 13/03/2010 19:02:23
OK I understand that. Now I see what I did. There is one other problem now. When I am at the 8th variable or 8th object that gets removed.
It changes room as if it was Hair == 9  ???

Yet when the variable is on 2,4 and 6 it does all the player.say commands as it should in order. 
Title: Re: Minigame Technique help.
Post by: monkey0506 on Sat 13/03/2010 20:13:42
Okay if you look at your code then you should see that in the hair3_UseInv function there is a Hair += 1; there in addition to calling RemoveHair. So:
Hair = 0
Use razor on hair 1
RemoveHair function is called
Hair = 1
stop
Use razor on hair 2
RemoveHair function is called
Hair = 2
Player says "This is a Span of hair"
stop
Use razor on hair 3
RemoveHair function is called
Hair = 3
Hair = 4
stop
Use razor on hair 4
RemoveHair function is called
Hair = 5
stop
Use razor on hair 5
RemoveHair function is called
Hair = 6
Player says "Seriously is this own a monkey yo!!"
stop
Use razor on hair 6
RemoveHair function is called
Hair = 7
Display "Ohh a six pack"
stop
Use razor on hair 7
RemoveHair function is called
Hair = 8
stop
Use razor on hair 8
RemoveHair function is called
Hair = 9
Player changes rooms
stop
Use razor on hair 9
RemoveHair function is called
Hair = 9
Player changes rooms
stop
If you don't understand where I came up with that, then I highly suggest you read a scripting tutorial or two, go back, and re-read your own code.

I'm not trying to be rude here, but scripting/programming is about 5% knowing the language and about 95% logic. Your logic is virtually non-existent. Correct your logic and your code will begin working properly.
Title: Re: Minigame Technique help.
Post by: Danman on Sun 14/03/2010 10:38:36
OK thanks monkey. What that was, Was the previous way I was going to script the puzzle then I changed it. I think I forgot to change that one.


Sorry I just forgot that I changed it. So I didn't check it again. 

Thanks a lot Monkey.