Three resources required to active

Discuss all aspects related to modding Zandronum here.
Post Reply
Capt.J3
 
Posts: 78
Joined: Wed Jun 06, 2012 1:51 pm
Location: United States

Three resources required to active

#1

Post by Capt.J3 » Sun Sep 06, 2015 11:57 am

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.
Spoiler: DON'T CLICK (Open)
But u did anyway... D:

User avatar
Hypnotoad
Retired Staff / Community Team Member
Posts: 528
Joined: Tue May 29, 2012 8:50 pm
Location: Britland

RE: Three resources required to active

#2

Post by Hypnotoad » Sun Sep 06, 2015 1:23 pm

Not sure exactly what you meant, but from a cursory glance you should probably remove the bracket (closing parentheses) immediately after CheckInventory("knowledge") > 99.

Catastrophe
Retired Staff / Community Team Member
Posts: 2569
Joined: Sat Jun 02, 2012 2:44 am

RE: Three resources required to active

#3

Post by Catastrophe » Sun Sep 06, 2015 2:00 pm

Are you sure the player is calling checkinventory and not the server? Also you have an extra parenthesis here: CheckInventory("knowledge") > 99)
Last edited by Catastrophe on Sun Sep 06, 2015 2:01 pm, edited 1 time in total.

Capt.J3
 
Posts: 78
Joined: Wed Jun 06, 2012 1:51 pm
Location: United States

RE: Three resources required to active

#4

Post by Capt.J3 » Sun Sep 06, 2015 4:22 pm

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?
Last edited by Capt.J3 on Sun Sep 06, 2015 4:25 pm, edited 1 time in total.
Spoiler: DON'T CLICK (Open)
But u did anyway... D:

User avatar
Ivan
Addicted to Zandronum
Posts: 2229
Joined: Mon Jun 04, 2012 5:38 pm
Location: Omnipresent

RE: Three resources required to active

#5

Post by Ivan » Sun Sep 06, 2015 4:39 pm

Count the brackets?
=== RAGNAROK DM ON ... uh... dead forever? ===
=== ALWAYS BET ON ... uh... dead forever? ===
=== Who wanta sum wang? ===
=== Death and Decay - A new Monster/Weapon replacer ===

Catastrophe
Retired Staff / Community Team Member
Posts: 2569
Joined: Sat Jun 02, 2012 2:44 am

RE: Three resources required to active

#6

Post by Catastrophe » Sun Sep 06, 2015 4:51 pm

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.
Last edited by Catastrophe on Sun Sep 06, 2015 4:51 pm, edited 1 time in total.

Konda
Forum Regular
Posts: 487
Joined: Thu Jun 07, 2012 5:22 pm

RE: Three resources required to active

#7

Post by Konda » Sun Sep 06, 2015 11:48 pm

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.

Code: Select all

<Synert> fuck
<Synert> plugged in my memory stick and got a bsod

Capt.J3
 
Posts: 78
Joined: Wed Jun 06, 2012 1:51 pm
Location: United States

RE: Three resources required to active

#8

Post by Capt.J3 » Tue Sep 08, 2015 12:07 am

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?
Spoiler: DON'T CLICK (Open)
But u did anyway... D:

Post Reply