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);
}
Indenting isn't the problem here. It's not using enough brackets to group commands.
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.
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.
HAI GUISE, U SERIOUS?
This thread is about proper indentation, how can you fuck that up?
My way:
function oMonster_UseInv() {
if (cDanny.ActiveInventory==iGun) {
DisplayAt (84,105,300, "Danny shoots the monster.");
FadeObjectOut(oMonster, 100, 1);
}
else {
...
}
}
Alternative:
function oMonster_UseInv()
{
if (cDanny.ActiveInventory==iGun)
{
DisplayAt (84,105,300, "Danny shoots the monster.");
FadeObjectOut(oMonster, 100, 1);
}
else
{
...
}
}
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.
When learning it is possible to mess up anything, no matter how simple.
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.