Help finding a work around instead of using blank objects as triggers for events

Started by danbuddle, Fri 14/03/2014 21:03:12

Previous topic - Next topic

danbuddle

Hello all,

I am really pleased with myself for creating my first fully functional puzzle!

Basically you have to burn some personal papers and a ID card in a toaster. However to do this you need to put some cotton wool in first to get a fire going in the toaster. Also, you can't start burning until both ID card and the personal papers are present in the toaster (along with the cotton wool.)

To achieve this I have been using blank objects (objects in the room with a blank picture so you can't see them) which are Visible = True when I put something in the toaster. So when the papers go in the toaster oBlank1.Visible = True, when the ID card goes in oBlank2.Visible = True and only then can you turn on the toaster and burn them.

Here is a snippet of the code to show:

Code: ags
function hHotspot8_UseInv()
{
if ((player.ActiveInventory == iIdentichip) && (oCwooltoaster.Visible == true) && (oBlank1.Visible == true))
{ 
cEgo.Walk(320, 150, eBlock);
cEgo.Say("OK, I've added the card to the toaster... Let's give it a try....");
cEgo.Say("...it's heating up alright...");
cEgo.Say("Shit, it's on fire!");
cEgo.Say("Ok, it's calming down... it's calming down.");
cEgo.Say("Alright its out, let's take a look...");
cEgo.Say("OK, they're gone. Not a trace bar some ash. That ought to slow down any hope or tracing me.");
player.LoseInventory(iIdentichip);
oBlank3.Visible = true;
return;
}
if ((player.ActiveInventory == iPapers) && (oCwooltoaster.Visible == true) && (oBlank2.Visible == true))
{ 
cEgo.Walk(320, 150, eBlock);
cEgo.Say("OK, I've added the papers to the toaster... Let's give it a try....");
cEgo.Say("...it's heating up alright...");
cEgo.Say("Shit, it's on fire!");
cEgo.Say("Ok, it's calming down... it's calming down.");
cEgo.Say("Alright its out, let's take a look...");
cEgo.Say("OK, they're gone. Not a trace bar some ash. That ought to slow down any hope or tracing me.");
player.LoseInventory(iPapers);
oBlank3.Visible = true;
return;
}
if ((player.ActiveInventory == iPapers) && (oCwooltoaster.Visible == true))
{ 
cEgo.Walk(320, 150, eBlock);
cEgo.Say("OK, I've crammed the papers into the toaster with the cotton wool.");
cEgo.Say("Now I just need my IDENTIchip card and we can be done with this dreadful business");
oBlank1.Visible = true;
player.LoseInventory(iPapers);
return;
}
if ((player.ActiveInventory == iIdentichip) && (oCwooltoaster.Visible == true))
{ 
cEgo.Walk(320, 150, eBlock);
cEgo.Say("OK, I've crammed the card into the toaster with the cotton wool.");
cEgo.Say("Now I just need my personal papers and we can be done with this dreadful business");
oBlank2.Visible = true;
player.LoseInventory(iIdentichip);
return;
}
if (player.ActiveInventory == iPapers)
{ 
cEgo.Walk(320, 150, eBlock);
cEgo.Say("Burn the papers in the toaster? OK, that could work...");
cEgo.Say("...It's not getting hot enough, it's only browned them. Damn.");
return;
}
if (player.ActiveInventory == iIdentichip)
{ 
cEgo.Walk(320, 150, eBlock);
cEgo.Say("Burn the card in the toaster? OK, that could work...");
cEgo.Say("...It's not getting hot enough, it's only browned it. Damn.");
return;
}
if (player.ActiveInventory == iCwool)
{ 
cEgo.Walk(320, 150, eBlock);
cEgo.Say("I've pressed it into the toaster. That should help to get some real heat going.");
oCwooltoaster.Visible = true;
player.LoseInventory(iCwool);
return;
}
}


Here you can see interacting with the toaster is limited by whether the cotton wool is present (oCottonwooltoaster = Visible) and whether or not the two items are in the toaster, triggering the blank objects.

My question is, is there an easier way to do this? The blank objects just seemed an obvious way to do this as I had no other indicators as to whether the Papers or ID card had been put in the toaster yet.

Hope I explained myself clearly either way.
Any advice much appreciated.
Ta.
I really have nothing to say...

DoorKnobHandle

Simple boolean variables will do the trick! You can read up on variables in the manual, on the forums here and in densming's Youtube tutorial series.

Dualnames

Code: ags

bool put_toaster =false;
bool blank1 = false;
bool blank2 = false;
bool puzzle_toast = false;

function hHotspot8_UseInv()
{
cEgo.Walk(320, 150, eBlock);


if (player.ActiveInventory == iPapers || player.ActiveInventory == iIdentichip)
{ 
if (!put_toaster)
{
cEgo.Say(String.Format("Burn the %s in the toaster? OK, that could work...", player.ActiveInventory.Name));
cEgo.Say("...It's not getting hot enough, it's only browned them. Damn.");
}
else 
{
if (player.ActiveInventory == iPapers)
{ 
if (!blank1)
{
cEgo.Say("OK, I've crammed the papers into the toaster with the cotton wool.");
cEgo.Say("Now I just need my IDENTIchip card and we can be done with this dreadful business");
blank1 = true;
player.LoseInventory(iPapers);
}
else 
{
if (blank2)
{
cEgo.Say("OK, I've added the papers to the toaster... Let's give it a try....");
cEgo.Say("...it's heating up alright...");
cEgo.Say("Shit, it's on fire!");
cEgo.Say("Ok, it's calming down... it's calming down.");
cEgo.Say("Alright its out, let's take a look...");
cEgo.Say("OK, they're gone. Not a trace bar some ash. That ought to slow down any hope or tracing me.");
player.LoseInventory(iPapers);
puzzle_toast = true;
}
}
}
else if (player.ActiveInventory == iIdentichip)
{
if (!blank2)
{
cEgo.Say("OK, I've crammed the card into the toaster with the cotton wool.");
cEgo.Say("Now I just need my personal papers and we can be done with this dreadful business");
blank2 = true;
player.LoseInventory(iIdentichip);
}
else 
{
if (blank1)
{
cEgo.Say("OK, I've added the card to the toaster... Let's give it a try....");
cEgo.Say("...it's heating up alright...");
cEgo.Say("Shit, it's on fire!");
cEgo.Say("Ok, it's calming down... it's calming down.");
cEgo.Say("Alright its out, let's take a look...");
cEgo.Say("OK, they're gone. Not a trace bar some ash. That ought to slow down any hope or tracing me.");
player.LoseInventory(iIdentichip);
puzzle_toast = true;
}
}
}
}
else if (player.ActiveInventory == iCwool)
{ 
cEgo.Say("I've pressed it into the toaster. That should help to get some real heat going.");
put_toaster=true;
player.LoseInventory(iCwool);
}
}


You may not like my way, but after shaping your code a bit towards my liking, it's apparent that you are missing interactions. I may have missed a bracket or made a parsing error.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

danbuddle

Thank you. The Boolean variables look much more economical. I noticed that the order of the ifs and else's is quite specific, is there a general rule for how to order the script? Looks like the function with the most variables attached to it needs to go first and so on in descending order. Is that right?
Regardless, thank you again, that's a big help and quite literally a 'game changer' (laugh)
I really have nothing to say...

Cassiebsg

Now I'm going a little off topic here, and comment on something you didn't ask, but I have too much time to think at work and this puzzle got me thinking....

Why do you think you need a cotton ball to start a fire on a toaster?
Trust me, put a paper and  plastic card in it, turn it on and they will burn... if you want flames just blow on it (I once started a fire in a toaster while trying to blow some bread crumbs off it ]). I have a felling that the cotton ball being needed to complete this puzzle will just annoy the player. ;) If you really want/need 3 items, then maybe his jacket name tag (or something else :) ).
If I was you I would keep the cotton ball to solve another puzzle... like maybe remove some paint with it along with some alcohol (just an idea, you can probably think of a thousand other ways it could be useful in another puzzle)...

PS - I'm no expert in making games (and I even haven't done any coding, if you don't count the tutorial), though played a lot of them... so take it as is, I maybe wrong about this... :)
There are those who believe that life here began out there...

Khris

Quote from: danbuddle on Sat 15/03/2014 06:37:40I noticed that the order of the ifs and else's is quite specific, is there a general rule for how to order the script?
No, but the logic has to be correct.
An else if block will only execute if none of the previous conditions were true, so depending on the conditions you use, the order might matter, or not.

A simple example would be a probability test like this:
Code: ags
  int a = Random(99);
  if (a < 10) miss(); // 10%
  else if (a < 90) hit(); // 80%
  else critical(); // 10%

If you changed the order of the first two, you'd have to use if (a >= 10 && a < 90), otherwise else if (a < 10) would never happen.

danbuddle

Cassiebsg: Feedback noted and much appreciated.

Khris: Yes, that makes more sense to me now. Ta very much. I was not using 'else' at all to start so my strings of code where getting very confused!
Back to work then!
I really have nothing to say...

Matti

This is a bit offtopic but I highly recommend to indent your code. It's nicer to look at and it's easier to keep track of the brackets.

Example:

Code: ags

if (){
  ...
}
else if (){
  ...
  if (){
    ...
  }
  else (){
    ...
  }
}

danbuddle

I really have nothing to say...

SMF spam blocked by CleanTalk