Indenting scripting

Started by dbuske, Wed 01/06/2011 21:06:33

Previous topic - Next topic

dbuske

I finally got a more advanced script to work.
I had a monster that the character had to shoot with a gun. Then the monster just  instantly fades out.
My problem with scripting is knowing when to indent code.

function oMonster_UseInv()
{
if (cDanny.ActiveInventory==iGun)
DisplayAt (84,105,300, "Danny shoots the monster.");
FadeObjectOut(oMonster,  100, 1);
}
What if your blessings come through raindrops
What if your healing comes through tears...

Atelier

Indenting isn't the problem here. It's not using enough brackets to group commands.

Code: ags

function oMonster_UseInv()
{
     if (cDanny.ActiveInventory == iGun)
     {
     DisplayAt(84,105,300, "Danny shoots the monster.");
     FadeObjectOut(oMonster, 100, 1);
     }
}


Add { } and it will execute the two lines in the brackets.

NickyNyce

Have you seen the Densming video's on utube ?  If not you should check them out...how to use ags part 1 through forty something?

You should probably change the subject to something like how to group command's also....make's life easier on other's searching the forum's for info.

At the very end of what Atelier gave you, you can also add an else also.

example:

function oMonster_UseInv()
{
     if (cDanny.ActiveInventory == iGun)
     {
     DisplayAt(84,105,300, "Danny shoots the monster.");
     FadeObjectOut(oMonster, 100, 1);
     }
else
    {
      cDanny.Say("That's not going to kill the monster");
     }
}
maybe then you can call it advanced scripting.. ;)
In the game I'm making, my character's name is also Danny.... :P ...out of all the names in the universe.

Khris

HAI GUISE, U SERIOUS?

This thread is about proper indentation, how can you fuck that up?

My way:
Code: ags
function oMonster_UseInv() {
  if (cDanny.ActiveInventory==iGun) {
    DisplayAt (84,105,300, "Danny shoots the monster.");
    FadeObjectOut(oMonster,  100, 1);
  }
  else {
    ...
  }
}


Alternative:
Code: ags
function oMonster_UseInv()
{
  if (cDanny.ActiveInventory==iGun)
  {
    DisplayAt (84,105,300, "Danny shoots the monster.");
    FadeObjectOut(oMonster,  100, 1);
  }
  else
  {
    ...
  }
}

Wyz

It boils down to: every line between { and } should get one tab more. In AGS the tabs will be converted to two spaces, so mind when you are deleting stuff that you are always on the right level (multitude of 2) with the spaces.
Life is like an adventure without the pixel hunts.

dbuske

When learning it is possible to mess up anything, no matter how simple.
What if your blessings come through raindrops
What if your healing comes through tears...

FamousAdventurer77

Quote from: dbuske on Fri 03/06/2011 22:05:16
When learning it is possible to mess up anything, no matter how simple.

Agreed. And that is indeed how we learn.
If you want to know the Bible's contents, just watch Lord of the Rings or listen to the last 8 Blind Guardian albums. It's pretty much the same thing.

SMF spam blocked by CleanTalk