Difference between revisions of "CInventory::hasRequirements"
From King Arthur's Gold Wiki
Shadlington (Talk | contribs) (Created page with "<onlyinclude> Checks 1 or 2 inventories to see if they have the given requirements, and writes any missing requirements into a given CBitStream. Returns true if the requirem...") |
Shadlington (Talk | contribs) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
<onlyinclude> | <onlyinclude> | ||
− | Checks | + | Checks if this inventory contains the given requirements, and writes any missing requirements into a given [[CBitStream]]. |
Returns true if the requirements are met, otherwise false. | Returns true if the requirements are met, otherwise false. | ||
</onlyinclude> | </onlyinclude> | ||
− | This | + | This essentially calls [[hasRequirements]] just for this inventory (passing null for the other inventory argument). |
− | + | ||
− | + | ||
− | + | ||
The requirements parameter is the [[CBitStream]] you're reading the requirements from. | The requirements parameter is the [[CBitStream]] you're reading the requirements from. | ||
The missing parameter is a [[CBitStream]] that any missing requirements will be written into. | The missing parameter is a [[CBitStream]] that any missing requirements will be written into. | ||
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> | ||
− | bool hasRequirements( | + | bool hasRequirements(CBitStream@ requirements, CBitStream@ missing) |
</syntaxhighlight> | </syntaxhighlight> | ||
− | Example from Entities/ | + | Example from Entities/Characters/Scripts/BuilderInventory.as: |
− | <syntaxhighlight lang="cpp" highlight=" | + | <syntaxhighlight lang="cpp" highlight="8"> |
− | void | + | void onCreateInventoryMenu( CInventory@ this, CBlob@ forBlob, CGridMenu @gridmenu ) |
{ | { | ||
− | + | CBitStream reqs, missing; | |
− | if ( | + | AddRequirement( reqs, "blob", "mat_stone", "Stones", 10 ); |
+ | CGridButton @button = gridmenu.AddButton( "$EmptyShop$", "Make Workshop", Builder::make_workshop ); | ||
+ | if (button !is null) | ||
{ | { | ||
− | + | if (this.hasRequirements( reqs, missing )) | |
− | + | SetButtonRequirementsText( button, reqs, false ); | |
− | + | else | |
− | + | SetButtonRequirementsText( button, missing, true ); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
Object method of: [[CInventory]] | Object method of: [[CInventory]] | ||
[[Category:Scripting]] | [[Category:Scripting]] | ||
[[Category:Object Methods]] | [[Category:Object Methods]] |
Latest revision as of 21:11, 19 August 2012
Checks if this inventory contains the given requirements, and writes any missing requirements into a given CBitStream.
Returns true if the requirements are met, otherwise false.
This essentially calls hasRequirements just for this inventory (passing null for the other inventory argument).
The requirements parameter is the CBitStream you're reading the requirements from.
The missing parameter is a CBitStream that any missing requirements will be written into.
bool hasRequirements(CBitStream@ requirements, CBitStream@ missing)
Example from Entities/Characters/Scripts/BuilderInventory.as:
void onCreateInventoryMenu( CInventory@ this, CBlob@ forBlob, CGridMenu @gridmenu ) { CBitStream reqs, missing; AddRequirement( reqs, "blob", "mat_stone", "Stones", 10 ); CGridButton @button = gridmenu.AddButton( "$EmptyShop$", "Make Workshop", Builder::make_workshop ); if (button !is null) { if (this.hasRequirements( reqs, missing )) SetButtonRequirementsText( button, reqs, false ); else SetButtonRequirementsText( button, missing, true ); } }
Object method of: CInventory