AddAmount() renovation

Bug reports and feature requests. New features can only be added to the current development version. Bug-fixes may be back-ported.

Current release: 099 / Current development: 100
Post Reply
Harley
Forum Regular
Posts: 360
Joined: Sat Mar 18, 2006 1:41 am
Location: Germany

AddAmount() renovation

Post by Harley »

Happy New Year to all!

Subj with AddAmount() is that function:
Return values
1 or error
Instead of another functions, from the same "family", like CreateItemAtLocation(), CreateItemInBackpack(), CreateItemInContainer() and etc. that return
Return values
Item Reference on success
I offer to make return value at AddAmount() also the same "Item Reference on success".

With best regards!
User avatar
CWO
POL Expert
Posts: 1158
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Re: AddAmount() renovation

Post by CWO »

But for AddAmount(), you're already passing an item reference so you already have it and don't need a new one whereas with the Create* commands, the item didn't previously exist.
Harley
Forum Regular
Posts: 360
Joined: Sat Mar 18, 2006 1:41 am
Location: Germany

Re: AddAmount() renovation

Post by Harley »

CWO wrote: Thu Jan 02, 2020 3:46 am But for AddAmount(), you're already passing an item reference so you already have it and don't need a new one whereas with the Create* commands, the item didn't previously exist.
Thanks CWO for your answer! Let me introduce next situation.

Before I pass an item reference, I search it with function and add it to the variable:

Code: Select all

var existing_stack := FindObjtypeInContainer( container, objtype, FINDOBJTYPE_ROOT_ONLY );
After, I check it. If such kind of item exists in my pack, I add new one to it:

Code: Select all

var it;
if( existing_stack )
	it := AddAmount( existing_stack, amount );
endif
And after, I want to return this variable "it" with it reference or return 0, if nothing was founded.

Code: Select all

if( it )
	return it;
else
	return 0;
endif
Yes, you are right, I don't need a new one item reference, I need only those, which I have already use, but from AddAmount().

Of course, I can use the "crutch" like:

Code: Select all

it := AddAmount( existing_stack, amount );
if( it )
	it := existing_stack;
endif
But like you understand, that isn't right and looking good.
Harley
Forum Regular
Posts: 360
Joined: Sat Mar 18, 2006 1:41 am
Location: Germany

Re: AddAmount() renovation

Post by Harley »

Big thanks Nando and Dev_GIB for support, and also Turley for my Master's work :P
https://github.com/polserver/polserver/ ... 1bae7d4a47
Tomi
POL Developer
Posts: 478
Joined: Tue Feb 21, 2006 5:08 pm

Re: AddAmount() renovation

Post by Tomi »

Sound to me like you were doing something like:

Code: Select all

var existing_stack := FindObjtypeInContainer( container, objtype, FINDOBJTYPE_ROOT_ONLY );
var it := AddAmount( existing_stack, amount );

if ( it )
 return existing_stack;
else
 return 0;
endif
Not sure as CWO wrote what need the new item reference for when we already have it. But doesnt matter really.
Post Reply