Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: stevo2024 on Tue 11/06/2024 00:33:26

Title: help with the command (if) and the (&)
Post by: stevo2024 on Tue 11/06/2024 00:33:26
Hi everyone looking for help with the following command

I'm making a game that one character collects one Item , say a gun and another character collects a item , say a Axe.

This is what i'm trying to do but get a error.

this is the scrip.

function room_RepExec()
{

if (cEGO.InventoryQuantity[iGUN.ID]==1){  && if (cJOE.InventoryQuantity[iAXE.ID]==1){

 gPUZ1.Visible = true;
}
else
gPUZ1.Visible = false;

}
}
=======================================

I know you can do this with Objects like

if (ocup.Visible == true && ojug.Visible == true){

is there anyway you can do the same but for character ?.

Thank you and hope someone can help with this.
Stevo2024
Title: Re: help with the command (if) and the (&)
Post by: Crimson Wizard on Tue 11/06/2024 00:56:09
You simply have a wrong syntax, you should use the same syntax as you did with your objects example:
Code (ags) Select
if (cEGO.InventoryQuantity[iGUN.ID]==1 && cJOE.InventoryQuantity[iAXE.ID]==1){

On another hand, if you really need two separate "ifs", then you should make a nested structure, without any "&&" in between:
Code (ags) Select
if (cEGO.InventoryQuantity[iGUN.ID]==1){
     if (cJOE.InventoryQuantity[iAXE.ID]==1){
          // do something here
     }
}
Title: Re: help with the command (if) and the (&)
Post by: Khris on Tue 11/06/2024 09:35:28
Note that a term like oCup.Visible == true is redundant; AGS does not read this like a human would, it simply calculates the result. Therefore, oCup.Visible == true is the exact same as oCup.Visible.

In other words, you can do
  gPUZ1.Visible = cEGO.HasInventory(iGUN) && cJOE.HasInventory(iAXE);