Source language: Translate to:

Capturing List Box List Items instead of Item Number

Questions about our Advanced Database plug-in

Moderator: Neosoft Support

Capturing List Box List Items instead of Item Number

Postby DantesGame » Mon Dec 14, 2015 11:00 am

Hi all,

I was hoping I could solicit some insight or help on how to capture the actual List Item selections (as a string) in a List Box instead of the Item Number that gets generated when sorting the list. Here's what I have for my button settings and action code:

List Box General properties:

List items:
---
Ax
Bastard Sword
Cudgel

Variable: [NPC_Details.NPCs.Weapon1]
Variable Contains: Item Number (1,2,3…)
Object Name: Weapon1Name

Actions:

FileRead "[PubDir]\tables\weapons_and_damage.csv" "[NPC_Details.NPCs.Weapon1]" "[ThisWeapon1]"
StrParse "[ThisWeapon1]" "," "[ThisWeapon1Value]" "[ThisWeapon1ValueCount]"

.NPC_Details.NPCs.Dmg1 records weapon damage in a Text Entry Field
SetVar "[NPC_Details.NPCs.Dmg1]" "[ThisWeapon1Value2]"

If "[weapon1]" "=" "7"
SetVar "[WMax]" "58"
GoSub "Random2"
Else
EndIf


When I select a weapon from the List Box, say Cudgel, the number 4 gets stored in my table instead of the word Cudgel. If I change the "Variable Contains:" to Item text, I get nothing recorded for the List Box selection and this shows up in my Text Entry field where the damage bonus is supposed to show up (see the note above for the first SetVar):
---Awl Pike

How can I set up the List Box so it 1. Grabs the List Item word/string and enters it into my db table and 2. It populates the [NPC_Details.NPCs.Dmg1] text entry field correctly like it does before I changed the "Variable Contains:" section? Thank you and I hope that makes sense.

-Efrem
DantesGame
 
Posts: 29
Joined: Sun Jun 08, 2008 1:15 pm

Re: Capturing List Box List Items instead of Item Number

Postby Gaev » Mon Dec 14, 2015 11:26 am

Efrem:

The reason you are getting nothing is because when NeoBook services this line ...
Code: Select all
FileRead "[PubDir]\tables\weapons_and_damage.csv" "[NPC_Details.NPCs.Weapon1]" "[ThisWeapon1]"

... it is expecting a line number in the second parameter ... but now [NPC_Details.NPCs.Weapon1] contains a string value of "Cudgel" ... which is not a number !!!

Leave the parameter ... Variable Contains: Item Number (1,2,3…) ... as is ... but in the first line of your Selection Changed event handler, insert this ...
Code: Select all
ListBoxGetItem "Weapon1Name" "[NPC_Details.NPCs.Weapon1]" "[NPC_Details.NPCs.Weapon1.Text]"

Now, [NPC_Details.NPCs.Weapon1.Text] will contain "Cudgel" ... and [NPC_Details.NPCs.Weapon1] will still contain the line number of the selected item.
User avatar
Gaev
 
Posts: 3738
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Capturing List Box List Items instead of Item Number

Postby DantesGame » Mon Dec 14, 2015 1:30 pm

Hi Gaev,

Thanks for the fast response as always. I used your tweaks and still came up with the item count number--then I threw in another line to set a new variable as shown below and it worked:

ListBoxGetItem "Weapon1Name" "[NPC_Details.NPCs.Weapon1]" "[NPC_Details.NPCs.Weapon1.Text]"

FileRead "[PubDir]\tables\weapons_and_damage.csv" "[NPC_Details.NPCs.Weapon1]" "[ThisWeapon1]"

StrParse "[ThisWeapon1]" "," "[ThisWeapon1Value]" "[ThisWeapon1ValueCount]"

SetVar "[NPC_Details.NPCs.Dmg1]" "[ThisWeapon1Value3]"

.This is the new line of code that sets my table field to the actual weapon name instead of count number
SetVar "[NPC_Details.NPCs.Weapon1]" "[NPC_Details.NPCs.Weapon1.Text]"

If "[weapon1]" "=" "7"
SetVar "[WMax]" "58"
GoSub "Random2"
Else

EndIf

Now the only quirk--that I can live with--is that when I'm generating a profile and I select a weapon, the List Box goes blank until I refresh the database, then it shows me that it saved the correct selection. Again, not a big deal but if you have any thoughts on that they'd be appreciated.

Thanks again!

-Efrem
DantesGame
 
Posts: 29
Joined: Sun Jun 08, 2008 1:15 pm


Return to NeoBookDBPro

Who is online

Users browsing this forum: No registered users and 2 guests