mIRC Home    About    Download    Register    News    Help

Print Thread
Hash Tables and Dialog Boxes - a 2 part problem #6006 10/01/03 11:11 PM
Joined: Jan 2003
Posts: 16
D
DynaMup Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Jan 2003
Posts: 16
I'm working on a project (an RPG utility) but have hit a brick wall, so I hope some of the more skilled IRC programmers out there can help me!

Here is my problem (it is in 2 parts):

1) A user is faced with a dialog box asking them to "Choose a Race", and when they click the "Next" button at the bottom of the screen, this information is saved to a Hash Table. Here is an example of my code:

on *:dialog:new1:sclick:13:{
if ($did(new1,9).state == 1) { hadd CharSheet Race Human }
}

That part works fine. However, in this instance, I also want the program to add some default skills to the "Character" being created, which will vary depending on their choice of race. Each <name> in Hash Tables needs to be unique (so, for example, { hadd CharSheet Skill Athletics | hadd CharSheet Skill Climbing } would only save "Climbing" to the Hash Table, as "Athletics" would be overwritten), so I don't think this is a viable option (however, I would love to be proved wrong!). What would be the best way to store this information so that it could be called upon by other scripts?

2) This information then displays on a "Character Sheet" (another dialog box). There are a few blank edit boxes set aside for these "Skills". I want the skills from the user's race selection to be displayed in these, one skill to each edit box. They don't need to be in any particular order, so I thought some sort of routine that checked to see if an edit box was empty would suffice - and if it was, it would write one skill to the box, and then find the next empty box for the next skill to be written into. Can anybody help me with this?

I apologise for being wordy and confusing, but this has frustrated me for days now. There is probably some blindingly simple solution that I'm overlooking, but any help that could be given (to either part of the problem) would be *greatly* appreciated!


A poor life this, if full of care,
We have no time to stand and stare.
Re: Hash Tables and Dialog Boxes - a 2 part problem #6007 10/01/03 11:28 PM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Have your hash table entry ADD to what's already there and then use $gettok() or $istok() later to parse it. smile

hadd CharSheet Skill Athletics
hadd CharSheet Skill $hget(CharSheet,Skill) Climbing

CharSheet
Skill=Althletics Climbing

Code:

  if ($istok($hget(CharSheet,Skill),Climbing,32)) { ; this character can climb }
  else { ; this character cannot climb }


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Re: Hash Tables and Dialog Boxes - a 2 part problem #6008 11/01/03 12:01 PM
Joined: Jan 2003
Posts: 16
D
DynaMup Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Jan 2003
Posts: 16
Thanks, Hammer - that certainly solved the first part of my problem. Now I have a group of skills entered into the Hash Table, all under the same heading of "Skill".

Now, the part that continues to fry my brain smile

I have a separate Dialog Box (named "sheet") where I have a series of empty edit boxes where I intend to display these skills, one to each edit box. How can I do this?

I assume the routine needs to be called during the on *:dialog:sheet:init:0 code for the dialog box. However, I cannot think of a way to devise a system that will take a "Skill" from the Hash Table and put it in an edit box, and then take another skill, and put it in the next blank edit box it finds.

If you could help me with -that- one, I'd be most grateful - I've gone cross-eyed trying to work it out! smile

Once again, many thanks for your help so far.


A poor life this, if full of care,
We have no time to stand and stare.
Re: Hash Tables and Dialog Boxes - a 2 part problem #6009 11/01/03 02:47 PM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
[color:000080]Strategy[/color]

Let's assume for the sake of this example (since you didn't say which ID was the listbox) that your listbox ID is 10 and that you have added these skills separated by a space $chr(32) as suggested earlier. You can use:

[*]$gettok( [color:#840017]value, 1, 32)[/color] returns the 1st Skill in value
[*]$gettok( [color:#840017]value, 2, 32)[/color] returns the 2nd Skill in value
[*]
[*]
[*]
[*]$gettok( [color:#840017]value, N, 32)[/color] returns the Nth Skill in value

where value is your $hget(CharSheet,Skill).

All you have to do is use a loop index like %i in place of the 1 in $gettok( [color:#840017]value, 1, 32)[/color]. You start %i at 1 and let it increment %i until it runs out of Skills in value to add to the listbox.

[color:000080]Script[/color]
Code:

on *:DIALOG:sheet:init:0:{
  var [color:#000080]%i[/color] = 1
  while ([color:#800090]$gettok( [color:#840017]$hget(CharSheet,Skill)[/color], [color:#000080]%i[/color], [color:#006600]32[/color])[/color]) {
    did -a $dname 10 $ifmatch
    inc [color:#000080]%i[/color]
  }
}

[color:000080]Colors[/color]

The garish colors were to help you track which numbers mean what in which positions throughout.

[color:000080]Listbox[/color]

I used a listbox rather than a series of editboxes for simplicity. A listbox is much better suited to this kind of task than is an editbox where the skill would be "editable," which is not, I think, what you had in mind.

One of the drawbacks is that you might end up with more skills than you have editboxes, whereas with a listbox, you can just keep adding till you add them all. If you wanted to, you could display Option settings for each skill that change as you sclick on each item in the listbox, perhaps disabling some enabling others, filling the appropriate controls with the data that's appropriate for that Skill.

If you really do want to use an editbox, then you will need an outer loop to loop through a tokenized list of editbox control IDs, such as 20:22:24:26:29:30:32:34:36 ... again, using $gettok to loop through each.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Re: Hash Tables and Dialog Boxes - a 2 part problem #6010 11/01/03 03:05 PM
Joined: Dec 2002
Posts: 191
N
Nobodi Offline
Vogon poet
Offline
Vogon poet
N
Joined: Dec 2002
Posts: 191
Hammer have you looked at /didtok at all.

Code:
 
 var %i = 1
  while ($gettok( $hget(CharSheet,Skill), %i, 32)) {
    did -a $dname 10 $ifmatch
    inc %i 
 }


could be replaced with.

Code:

 didtok $dname 10 32 $hget(CharSheet,Skill)

Re: Hash Tables and Dialog Boxes - a 2 part problem #6011 11/01/03 05:25 PM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Yup, I know about /didtok. I wanted to keep the script "relatively" easily modifiable if he decided he wanted to go with editboxes after all. /didtok would definitely be the way to go for a listbox, though. smile


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Re: Hash Tables and Dialog Boxes - a 2 part problem #6012 11/01/03 05:57 PM
Joined: Jan 2003
Posts: 16
D
DynaMup Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Jan 2003
Posts: 16
Once again, many thanks guys. As you've probably guessed, this is all a steep learning curve for me, but I'm getting there!

I've reviewed my options and decided that a ListBox would be just fine for storing this kind of data, and it'll make things much more convenient for me. It'll also be more practical for storing the data associated with each skill - as you probably know already, if someone has an "Athletics" skill in an RPG, there's bound to be some "Level" number or something to show the character's proficiency with that skill.

I'm going to go and do some heavy work and tweaking right now, but I'll report back and let you know how it went.

Once again, thanks guys smile


A poor life this, if full of care,
We have no time to stand and stare.
Re: Hash Tables and Dialog Boxes - a 2 part problem #6013 11/01/03 06:43 PM
Joined: Jan 2003
Posts: 16
D
DynaMup Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Jan 2003
Posts: 16
Oh - and one other thing...now I'm using:

Code:
 
didtok sheet 47 $hget(CharSheet, Skill)
 


But I'm finding that it's only adding the last item under "Skill" in the hash table to my listbox. I want it to add the entire list of items. Help! smile


A poor life this, if full of care,
We have no time to stand and stare.
Re: Hash Tables and Dialog Boxes - a 2 part problem #6014 11/01/03 08:13 PM
Joined: Jan 2003
Posts: 16
D
DynaMup Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Jan 2003
Posts: 16
Arrrgh! I've basically started a conversation with myself. Don't worry about what I said earlier...I just realised that I forgot to use the 32 delimiter smile


A poor life this, if full of care,
We have no time to stand and stare.