Is it possible to use a bool within a bool? (Solved.)

Started by Fluxpuppy, Fri 02/01/2015 14:48:37

Previous topic - Next topic

Fluxpuppy

For example, there is an obstacle in-front of a box, I use a bool to tell the box the obstacle is moved and i can take item from it, then another bool within that one to check if I have the item in the box, so i can't keep picking it up over and over.
I guess its impossible because of the brackets but maybe their is something i'm missing.

This is what i'm trying but i'm getting an obvious error of a missing closing bracket but then that would create a separate command? headache. :confused:
Sorry for my ignorance, I only just  started learning code a week or so ago.

Code: ags

function hHotspot4_Interact()
{
 if (headonshoulders == false) {
 cgarth.Say("It's full of fireworks!"); 
  if (takenfwork == false){
    cgarth.Say("I'll take one.);
    cgarth.AddInventory(ifirework); 
    takenfwork = true; }
    
 
 else {  cgarth.Say("The sleeping man is in the way."); }
}
I eat a lot of garlic to be honest

Andail

#1
Code: ags

function hHotspot4_Interact()
{
if (headonshoulders == false) {
    cgarth.Say("It's full of fireworks!"); 
    if (takenfwork == false){
        cgarth.Say("I'll take one.");
        cgarth.AddInventory(ifirework); 
        takenfwork = true; 
    }
}
else cgarth.Say("The sleeping man is in the way."); 
}


I exaggerated the indentations here to show where they should be. The only error I spotted was a lacking end quote on line 6.

PS:
I realised that you probably meant for the "The sleeping man..." etc to appear when headonshoulders is true? In that case I've now changed the brackets so that the conditions work.

geork

Hello Fluxpuppy,

You can definitely have a bool check inside another bool check - just make sure to format it properly so that you can understand how 'deep' you are at any point. Here you are missing a second closing bracket to close of your first if statement. Your code here is also missing the double quotation marks in line 6, so your string is over-running until line 11.

Code: ags
function hHotspot4_Interact()
{
 if (headonshoulders == false) { //If statement 1
 cgarth.Say("It's full of fireworks!");
 if (takenfwork == false){ //If statement 2
   cgarth.Say("I'll take one.");
   cgarth.AddInventory(ifirework);
   takenfwork = true; } //Closes off If statement 2
 else {  cgarth.Say("The sleeping man is in the way."); } //Else statement to If statement 2
                                                           //Note: I have indented it here to match If statement 2
 } //You were missing a this to close off If statement 1
}


EDIT: Beaten by Andail :)

EDIT 2: If Andail is correct about the sleeping man, then this code is wrong anyway :P

Fluxpuppy

Thanks guys, how did I miss the end quote!
It was the closing bracket for the first statement that was messing with me, It's all working now.
The headonshoulders false was fine, that was true before the head was removed from the shoulder in a character script. (don't ask :wink: )
I eat a lot of garlic to be honest

Crimson Wizard

I would also like to point out, that there are simplier expressions for boolean variables:

1. Instead of if (var == true) you can do just if (var)
2. Instead of if (var == false) you can do just if (!var) (note the ! sign -- it means "NOT").

Fluxpuppy

Oh, Thankyou.
I hadn't come across that anywhere, I'll take that on board. :)
I eat a lot of garlic to be honest

SMF spam blocked by CleanTalk