Difference between revisions of "Multiple Inventory Items"

From AGI Wiki
Jump to navigationJump to search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[AGI Tutorials|Tutorials Table of Contents]]<br />
+
[[Tutorials and Guides|Tutorials and Guides Table of Contents]]<br />
  
 
<div align="center"><span style="font-size: 22pt">Multiple Inventory Items</span><br />
 
<div align="center"><span style="font-size: 22pt">Multiple Inventory Items</span><br />
''By [[]]''</div>
+
''By [[Andrew Baker]]''</div>
  
 
&nbsp;
 
&nbsp;
  
In [[Voodoo Girl]], I decided to give the player the ability to carry around more than one of each particular item. But how to do so?! I wracked my brain, stayed up all night, and pulled my hair out. Eventually, I just turned on my computer and typed in some code. Hmm, guess I should have tried that first.
+
In [[Voodoo Girl: Queen of the Darned|Voodoo Girl]], I decided to give the player the ability to carry around more than one of each particular item. But how to do so?! I wracked my brain, stayed up all night, and pulled my hair out. Eventually, I just turned on my computer and typed in some code. Hmm, guess I should have tried that first.
  
 
First I added the name of my item as a variable in defines.txt:
 
First I added the name of my item as a variable in defines.txt:
Line 44: Line 44:
 
&nbsp;
 
&nbsp;
  
[[AGI Tutorials|Tutorials Table of Contents]]
+
[[Tutorials and Guides|Tutorials and Guides Table of Contents]]
  
 
&nbsp;
 
&nbsp;
  
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]
 +
[[Category:References]]

Latest revision as of 16:29, 26 December 2013

Tutorials and Guides Table of Contents

Multiple Inventory Items
By Andrew Baker

 

In Voodoo Girl, I decided to give the player the ability to carry around more than one of each particular item. But how to do so?! I wracked my brain, stayed up all night, and pulled my hair out. Eventually, I just turned on my computer and typed in some code. Hmm, guess I should have tried that first.

First I added the name of my item as a variable in defines.txt:

#define moss v60

Then I created a new logic that is called from Logic.000 at the end of every cycle.

call(200);

In the body of this new logic I wrote:

Code:

<syntaxhighlight lang="agi">

  1. include defines.txt
   if (moss > 0 && !has("moss"))
   {
       get("moss");
   }
   if (moss == 0 && has("moss"))
   {
       drop("moss");
   }

</syntaxhighlight>

Last, and certainly not least, to add a nice touch, I altered the description of my inventory in the view editor:

You have %v60 pieces of moss.

Just prefix the variable with % to have it print out with your show.obj() description or to embed it in a string (i.e. print("You have %60 pieces of moss");).

Happy coding!

 

Tutorials and Guides Table of Contents