Minigame Technique help.

Started by Danman, Wed 10/03/2010 16:03:25

Previous topic - Next topic

Danman

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)







Mouth for war

#1
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?
mass genocide is the most exhausting activity one can engage in, next to soccer

Danman

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.



Mouth for war

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 ;
}
mass genocide is the most exhausting activity one can engage in, next to soccer

Danman

#4
But how will that work with all 18. Do I do
like
Code: ags

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



barefoot

Hi

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

Code: ags


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

I May Not Be Perfect but I Have A Big Heart ..

barefoot

#6
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:

Code: ags

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
I May Not Be Perfect but I Have A Big Heart ..

Danman

#7
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 .



Danman

OK I tested this now and this is what I did

Code: ags


// 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  :-\



barefoot

adjust to:

Code: ags

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


barefoot
I May Not Be Perfect but I Have A Big Heart ..

Khris

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.

monkey0506

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).

tzachs

Another problem in your code is missing brackets, change the use inv functions like this:
Code: ags

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

Danman

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.



Khris

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.

Danman

This was in the room script.

Code: ags


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.



Khris

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.

Danman

#17
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

Code: ags


if (Hair == 2) 

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




Khris

You can leave it inside repeatedly_execute, a better way though is to check each time you turn off a hair object.

Code: ags
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.

Code: ags
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.

Danman

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.

Code: ags

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



SMF spam blocked by CleanTalk