help with the command (if) and the (&)

Started by stevo2024, Tue 11/06/2024 00:33:26

Previous topic - Next topic

stevo2024

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

Crimson Wizard

#1
You simply have a wrong syntax, you should use the same syntax as you did with your objects example:
Code: ags
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
if (cEGO.InventoryQuantity[iGUN.ID]==1){
     if (cJOE.InventoryQuantity[iAXE.ID]==1){
          // do something here
     }
}

Khris

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
Code: ags
  gPUZ1.Visible = cEGO.HasInventory(iGUN) && cJOE.HasInventory(iAXE);

SMF spam blocked by CleanTalk