Hi Petr,
Sorry still don't get it!
What exactly is dictionary?
Look to be good idea I could use in adventure.
I've been out out tonite and had a few drinks so not thinking properly!
catventure
Hi Catventure,
use is quite general.
Take this example:
[code=thinbasic]
USES "dictionary"
Dim pInventoryDict As Long ' -- Pointer to dictionary
%NUM_Characters = 3
pInventoryDict = Dictionary_Create(%NUM_Characters * 2) ' -- Character name + inventory
Dictionary_Add(pInventoryDict, "Old orc", "Axe, Sword, Deodorant")
Dictionary_Add(pInventoryDict, "Wizard", "Magic wand, Beard dummy")
Dictionary_Add(pInventoryDict, "Woodpecker", "Red hat")
Msgbox 0, "Wizard invenotry is:"+$CRLF+$CRLF+Dictionary_Find(pInventoryDict, "Wizard")
Dictionary_Free(pInventoryDict)
[/code]
... in this case you can use it like array, but instead of numeric index use directly name of character
Bye,
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Hi Petr,
Sorry still don't get it!
What exactly is dictionary?
Look to be good idea I could use in adventure.
I've been out out tonite and had a few drinks so not thinking properly!
catventure
http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)
Hi,
this was just one example, maybe not the best.
I will try to take a glass of Jameson and see if it can be understood differentely then ;D
Imagine you need to store some data, which can be hardly indexed using numbers.
You can still do that using arrays + equates, to keep it clear, but this is not as universal.
So you can index items using strings, this is how I understand it
Eros released new thinBASIC preview with nice example on dictionaries, worth to have a look !
Bye,
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Thanks Psch,
I have recovered a bit from last night
I understand your example better now. Very good.
Well this definitely opens up some new possibilities, and I wasn't expecting anything like this to be added to thinBasic, so fantastic job!
catventure
http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)
he he ;D
I lived in London for one year working for a multinational company.
Because I do not drink any alchool (beer included) I remember my "emargination" during first months. Most couldn't bealive I didn't drink anything other than water :P
Than people started to appreciate my no alchool attitude. I was always the "driver" to get them home.
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
I am happy you can see it now
;D Eros, this is nice story!
Bye,
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Petr, I don't understand this code:
%NUM_Characters = 3
pInventoryDict = Dictionary_Create(%NUM_Characters * 2) ' -- Character name + inventory
Why not:
pInventoryDict = Dictionary_Create(3 * 2)
or
pInventoryDict = Dictionary_Create(6)
or
pInventoryDict = Dictionary_Create(3 * sizeof(char)) : I don't understand where the 3 comes from when the words are much longer characters than 3 or 3*2 of 6 characters?
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Ken,
it is always good programming practice to define constants (rather than writing fixed numbers) even if it will be longer or boring.
This mainly for 2 important factors: readability and maintainability.
Readability:
it give much more sense to read something like %MaxNumberOfEnemies rather than something like 10 or 6 or 100
Maintainability:
if along the code you need to use again that constant it will be much, much more easy to maintain just a constant value rathar then searching all the code for all the places where you use a number and change it.
Also consider len of variable will not make any difference in compiled languages and a minimum difference in thinBasic too because every token is just parsed once.
So, use all the power of the language to always create code to be readable and maintanable.
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Thanks Eros, can you explain where the 3 and 2 came from to size the dictionary with the create command, how do you determine those values?
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Hi kryton,
it is simple, we have 3 characters...
Each of them has assigned some data ( inventory ).
So if we need 3 entries for names to dictionary, we will use numberOfCharacters + numberOfInventories. As number of inventories is the same as numberOfCharacters, I put there * 2. It is always about pair of data. So keys * 2.
This is also explained under thinBasic language / Modules / Dictionary / Dictionary_Create in help file.
You can imagine it as "How many cells I need to stor following?":
"Old orc""Axe, Sword, Deodorant"
"Wizard""Magic wand, Beard dummy"
"Woodpecker""Red hat"
Bye,
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Bookmarks