Page 1 of 1
Three resources required to active
Posted: Sun Sep 06, 2015 11:57 am
by Capt.J3
Ok. I am creating a script that would generate a building that can product a resource; However, It requires three resources to active the script.
But the problem is that I cannot find a way that would allow the requirement of three expressions. I know how to make it work with only one or two expressions; however, I am stuck trying to make it work with three.
May I have help please?
Spoiler: Here's the script (Open)
script 6 (void)
{
if (CheckInventory("gold") > 149 && CheckInventory("knowledge") > 99) && CheckInventory("wood") > 99)
{
takeInventory("gold", 150);
takeinventory("knowledge", 100);
takeinventory("wood", 100);
Print (s:"improved Farms, Food production increased!");
while(foodupgrade1 > 0)
{
GiveInventory("food", 1);
delay (6);
}
}
else if (farmhouse == 1 && CheckInventory("gold") > 199)
{
Floor_RaiseByValue (6, 255, 200);
takeInventory("gold", 200);
giveinventory("knowledge", 150);
Print (s:"technology researched, Now increased food production is available!");
foodupgrade1 ++;
delay(2);
}
else
{
print(s:"You need 200 Gold to purchase this upgrade. 150 Gold, 100 wood and 100 knowledge for upgrade two.");
}
}
Thanks.
RE: Three resources required to active
Posted: Sun Sep 06, 2015 1:23 pm
by Hypnotoad
Not sure exactly what you meant, but from a cursory glance you should probably remove the bracket (closing parentheses) immediately after CheckInventory("knowledge") > 99.
RE: Three resources required to active
Posted: Sun Sep 06, 2015 2:00 pm
by Catastrophe
Are you sure the player is calling checkinventory and not the server? Also you have an extra parenthesis here: CheckInventory("knowledge") > 99)
RE: Three resources required to active
Posted: Sun Sep 06, 2015 4:22 pm
by Capt.J3
Ah, It works! Thanks a lot you guys! I can't believe it was something this small, Well, I am a mapper not a coder! lol
By the way, how do you guys know all of this... "grammar coding"? how would I know that the ")" was the thing ruining my code?
RE: Three resources required to active
Posted: Sun Sep 06, 2015 4:39 pm
by Ivan
Count the brackets?
RE: Three resources required to active
Posted: Sun Sep 06, 2015 4:51 pm
by Catastrophe
Capt.J3 wrote:
how would I know that the ")" was the thing ruining my code?
Well you gotta count the parenthesis and make sure they're even. So if you have a total of four ('s on the left side, you need to make sure you also have 4 )'s on the right side also. I like to think of parenthesis as a "container".
It's something you get the hang of with experience, just keep at it.
RE: Three resources required to active
Posted: Sun Sep 06, 2015 11:48 pm
by Konda
Main point of the topic aside, I'd advise using the greater-than-or-equal-to operator ">=" with an exact amount of inventory required for purchase instead of the greater-than operator ">". It makes more sense, the code is less complicated, the code will be less complicated in the future if you decide to extend its functionality (for example replacing the constant-valued inventory prices with variables).
In your particular example, using the greater-than operator is not a big deal but if it becomes a habit it will bite you when you get to write more complicated code.
Oh yeah, if you're not really interested in coding and just want to make your map work then sorry for having my post waste your time lol.
RE: Three resources required to active
Posted: Tue Sep 08, 2015 12:07 am
by Capt.J3
Konda wrote:
In your particular example, using the greater-than operator is not a big deal but if it becomes a habit it will bite you when you get to write more complicated code.
Hello Konda,
Hmm, I do want to be able to make a more complicated code in the future... what would you recommend me using instead?