Keyboard Shortcuts
Likes
Search
Arrays to track count?
I am working on my own random gem table combining the 1ed DMG and articles from Dragon Magazine. I am able to loop through my initial?table, but that is spitting out one gem at a time.? Arrays have never been my strong suit in programming, and that has me at a disadvantage here. What I would like to do is when table generates: diamond, diamond, ruby, emerald, ruby to use the array to store and track the count of the results. so when I list out the results I can display 2x diamonds, 2x rubies, 1x emerald. Is this possible?? I was thinking?of something like this {DSCreate~Gems, GemID, Count}?? If I were in my SQL environment, I would just create a temp table and store each individual entry, then query for the counts.?? Thanks. |
That's definitely a way to do it. I know I've done exactly that in one of my tables way back when (for treasure generation), but I wasn't able to find it with a quick look. There might be an example in the Files section of the group. If I recall, the way I did it was to store the results in a dataset, and when each item was generated, I'd scan the dataset to see if it was already there. If so, I just incremented the count by one. If not, I created a new record with a count of one. ©\©\©\©\©\©\©\ Original Message ©\©\©\©\©\©\©\ On Tuesday, March 30, 2021 9:05 AM, Otaku Smurf <otakusmurfgaming@...> wrote:
|
I've only done a little bit with DS functions myself, but per the help file you need to include the default values in DSCreate
toggle quoted message
Show quoted text
{DSCreate~Gems,GemID,xxxx,Count,1} which sets up an empty array/temp table. Then when you spit out a new gem, you put it in a variable, e.g. NewGemID Then you use {DSFind~Gems,1,GemID=%NewGemID%} to find the index of that gem type if it exists, (-1 if it doesn't) If it doesn't exist, use {DSAdd~Gems,GemID,%NewGemID%} to add the gem (with the Count being 1 because we set it as the default). If it does exist, use {DSGet~Gems,%SavedIndexValueFound%,Count} to get the count, increment it by 1, and use {DSSet~Gems,%SavedIndexValueFound%,Count,%NewCountValue%} to save it again. So {DSSet~Gems,%SavedIndexValueFound%,Count,{Calc~{DSGet~Gems, %SavedIndexValueFound%,Count}+1}} to lump the last in a nested function. Erol K. Bayburt ErolB1@... On 3/30/2021 9:05 AM, Otaku Smurf wrote:
I am working on my own random gem table combining the 1ed DMG and articles from Dragon Magazine. |
Erol, Perfect.? I think I can wrap my head around that.?? On Tue, Mar 30, 2021 at 11:09 AM ErolB1 via <ErolB1=[email protected]> wrote: I've only done a little bit with DS functions myself, but per the help |
Ok, I am just working a small test before I toss in the really big random table.? When I run this, I get an output like:
1 2 Emerald 3 1500 Ruby 1 2500 The first 1 and 2 are the index values.?? How can I stop those from being displayed?? I cannot for the life of me figure out where I am "printing" the index numbers.? Here is my code: #Declare Data Set
%Treasure%, 1
?
#Declare Variables
%TreasureType%, 0
%Quantity%, 0
%GoldValue%, 0
%NumRecs%, 0
%Index%, 1
%SavedIndex%, 0
?
?
:Start
1, {DSCreate~Treasure,TreasureType,NONE,Quantity,0,GoldValue,0}
_{Loop~4,[Generate1]} [Display]
?
:Generate1
1,|TreasureType=Diamond||Quantity=1||GoldValue=5000| [AddItem]
2,|TreasureType=Ruby||Quantity=1||GoldValue=2500| [AddItem]
3,|TreasureType=Emerald||Quantity=1||GoldValue=500| [AddItem]
4,|TreasureType=Sapphire||Quantity=1||GoldValue=750| [AddItem]
5,|TreasureType=Topaz||Quantity=1||GoldValue=200| [AddItem]
?
:AddItem
1,|SavedIndex={DSFind~Treasure,0,TreasureType=%TreasureType%}|
_{If~%SavedIndex%<0?
_{DSAdd~Treasure,TreasureType,%TreasureType%,Quantity,%Quantity%,GoldValue,%GoldValue%}/
_{DSSet~Treasure,%SavedIndex%,Quantity,{Calc~{DSGet~Treasure,%SavedIndex%,Quantity}+%Quantity%}}
_{DSSet~Treasure,%SavedIndex%,GoldValue,{Calc~{DSGet~Treasure,%SavedIndex%,GoldValue}+%GoldValue%}}}
?
:Display
1, |Index=1||NumRecs={DSCount~Treasure}|
_{Loop~%NumRecs%,
_|TreasureType={DSGet~Treasure,%Index%,TreasureType}|%TreasureType%?
_|Quantity={DSGet~Treasure,%Index%,Quantity}|%Quantity%?
_|GoldValue={DSGet~Treasure,%Index%,GoldValue}|%GoldValue%{CR~}
_|Index+1|} |
In the :AddItem group you're using DSAdd, which returns the index of the entry added. You need to use DSAddNR which does not return any value.
toggle quoted message
Show quoted text
(I'd forgotten about that when I gave the example using DSAdd earlier.) Or you could get clever and replace {DSAdd~Treasure,TreasureType,%TreasureType%,Quantity,%Quantity%,GoldValue,%GoldValue%} with |NumRecs={DSAdd~Treasure,TreasureType,%TreasureType%,Quantity,%Quantity%,GoldValue,%GoldValue%}| which will save you from having to do |NumRecs={DSCount~Treasure}| in the :Display group. Erol K. Bayburt ErolB1@... On 4/6/2021 4:37 PM, Otaku Smurf wrote:
Ok, I am just working a small test before I toss in the really big random table.? When I run this, I get an output like: |
¿ªÔÆÌåÓýThere is a special version of DSAdd that does not give you a printed value¡ DSAddNR~ NR for No Return value ? Vance ? Sent from for Windows 10 ? From: ErolB1 via groups.io
Sent: Tuesday, April 6, 2021 5:59 PM To: [email protected] Subject: Re: [TableSmith] Arrays to track count? ? In the :AddItem group you're using DSAdd, which returns the index of the entry added. You need to use DSAddNR which does not return any value. ? (I'd forgotten about that when I gave the example using DSAdd earlier.) ? Or you could get clever and replace {DSAdd~Treasure,TreasureType,%TreasureType%,Quantity,%Quantity%,GoldValue,%GoldValue%} ? with ? |NumRecs={DSAdd~Treasure,TreasureType,%TreasureType%,Quantity,%Quantity%,GoldValue,%GoldValue%}| ? which will save you from having to do |NumRecs={DSCount~Treasure}| in the :Display group. ? ? Erol K. Bayburt ErolB1@... ? On 4/6/2021 4:37 PM, Otaku Smurf wrote: > Ok, I am just working a small test before I toss in the really big > random table.? When I run this, I get an output like: > 1 2 Emerald 3 1500 > Ruby 1 2500 > > The first 1 and 2 are the index values. > > How can I stop those from being displayed?? I cannot for the life of me > figure out where I am "printing" the index numbers.? Here is my code: > > #Declare Data Set > %Treasure%, 1 > #Declare Variables > %TreasureType%, 0 > %Quantity%, 0 > %GoldValue%, 0 > %NumRecs%, 0 > %Index%, 1 > %SavedIndex%, 0 > :Start > 1, {DSCreate~Treasure,TreasureType,NONE,Quantity,0,GoldValue,0} > _{Loop~4,[Generate1]} [Display] > :Generate1 > 1,|TreasureType=Diamond||Quantity=1||GoldValue=5000| [AddItem] > 2,|TreasureType=Ruby||Quantity=1||GoldValue=2500| [AddItem] > 3,|TreasureType=Emerald||Quantity=1||GoldValue=500| [AddItem] > 4,|TreasureType=Sapphire||Quantity=1||GoldValue=750| [AddItem] > 5,|TreasureType=Topaz||Quantity=1||GoldValue=200| [AddItem] > :AddItem > 1,|SavedIndex={DSFind~Treasure,0,TreasureType=%TreasureType%}| > _{If~%SavedIndex%<0? > _{DSAdd~Treasure,TreasureType,%TreasureType%,Quantity,%Quantity%,GoldValue,%GoldValue%}/ > _{DSSet~Treasure,%SavedIndex%,Quantity,{Calc~{DSGet~Treasure,%SavedIndex%,Quantity}+%Quantity%}} > _{DSSet~Treasure,%SavedIndex%,GoldValue,{Calc~{DSGet~Treasure,%SavedIndex%,GoldValue}+%GoldValue%}}} > :Display > 1, |Index=1||NumRecs={DSCount~Treasure}| > _{Loop~%NumRecs%, > _|TreasureType={DSGet~Treasure,%Index%,TreasureType}|%TreasureType% > _|Quantity={DSGet~Treasure,%Index%,Quantity}|%Quantity% > _|GoldValue={DSGet~Treasure,%Index%,GoldValue}|%GoldValue%{CR~} > _|Index+1|} > _._,_._,_ > ------------------------------------------------------------------------ ? ? ? ? ? |