[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  VBscript
. . -> [Subject]  Handling numerous speedwalks - and using a database

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Handling numerous speedwalks - and using a database
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  3  4  

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Thu 07 Nov 2002 02:26 AM (UTC)  quote  ]
Message

I have now written a lengthy plugin to demonstrate creating a database, creating a table, adding data, getting it back, deleting it, and general actions on it.

See Plugin that accesses a database


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Tue 01 Oct 2002 12:05 AM (UTC)  quote  ]
Message
Try doing it into a variable and displaying that. eg.

x = "INSERT INTO Items (Item ... blah blah ...
world.note x
db.Execute x

That way you can see if the SQL looks OK.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Ishnaf   Australia  (17 posts)  [Biography] bio
Date Mon 30 Sep 2002 01:24 PM (UTC)  quote  ]

Amended on Mon 30 Sep 2002 01:29 PM (UTC) by Ishnaf

Message
Thanks for those files, but now i have yet another question:

I've been attempting to make an item database.... It gets the item info from the mud and stores it in variables, passes this to the active x control, and then *should* pass it into a database. I figure its probably my coding, and i know the problem is in the active X, but not what it is :P. Here it is (i've added comments in !signs)

Public theworld As World

Sub GetStuff(theworld As World)
Dim object, itemtype, itemis, forgelvl, diceno, dicesize, !etc!



object = theworld.GetVariable("Object")
itemtype = theworld.GetVariable("ItemType")

!This is supposed to make one big field out of several variables!
itemis = theworld.GetVariable("ItemIs") + _
theworld.GetVariable("Savingpara") + _
theworld.GetVariable("Savingspell") + _
theworld.GetVariable("Poison") + _
theworld.GetVariable("spell") + _
theworld.GetVariable("abilities") + _
theworld.GetVariable("capacity")

forgelvl = theworld.GetVariable("ForgeLvl")
diceno = theworld.GetVariable("DiceNo")
dicesize = theworld.GetVariable("DiceSize")
!and etc!


Dim db
Set db = CreateObject("ADODB.Connection")

' Open the connection
db.Open = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Program Files\MUSHclient\ishnaf\DBproject\newdatabase.mdb"

db.Execute "INSERT INTO Items (Item, ItemType, ItemIs, ForgeLevel, DiceNo, DiceSize, Weight, Value, Rent, ACApply, Armor, CON, INT, WIS, DEX, CHA, STR, Hitroll, Damroll, maxhit, maxmana, Uselevel, Age) VALUES (" & _
"""" & Item & """, " & _
"""" & itemtype & """, " & _
"""" & itemis & """, " & _
"""" & ForgeLevel & """, " & _
"""" & diceno & """, " & _
!"""" & all the other bits& """, " & _!
"""" & dicesize & """ );"

db.Close
Set db = Nothing
End Sub



Hope you can understand that :)

egads!
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Sun 29 Sep 2002 09:56 PM (UTC)  quote  ]
Message
I haven't actually returned to this project since recieving the file from Nick. It's rather low priority for me so there is no hurry, although pretty educational as well, so I probably will get around to it sooner or later.

Your E-mail address is private in your bio, so I can't mail it to you. Mine is private too, so you can't mail me....

Ok, download it here: http://www.MagnumsWorld.com/ftp/AODitems.zip

I can't guarantee the file will stay there long term.


Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

Posted by Ishnaf   Australia  (17 posts)  [Biography] bio
Date Sun 29 Sep 2002 04:07 PM (UTC)  quote  ]
Message
Gday People.

I was wondering if i could get a copy of some of the files you used to create this project- I'm having similar sorts of trouble in my speedwalking project (see browsers and mushclient post). When I manage to get my program done i'll let everyone know...

egads!
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Fri 13 Sep 2002 10:17 PM (UTC)  quote  ]
Message
OK, I emailed it to you. I did a query to show how you would get the list of weapon types back in a single query.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Fri 13 Sep 2002 04:16 PM (UTC)  quote  ]
Message
Yes, please mail it back to me. :)

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Fri 13 Sep 2002 05:23 AM (UTC)  quote  ]
Message
Quote:

Are there any measures in place to keep me (the user) from selecting the same damage type twice within the sub-form?


The combination of weapon/damage is the primary key, and you cannot have two primary keys the same, thus an attempt to add two of them will be rejected by Access.

You can have the modified database back if you want.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Fri 13 Sep 2002 05:11 AM (UTC)  quote  ]
Message
Oops, I went back to look at page 3, and forgot there was a page 4.

That looks pretty good, Nick. I kind of wanted to display my own form window like you did, but only you can do that. :)

Are there any measures in place to keep me (the user) from selecting the same damage type twice within the sub-form? If it's not built in, I assume I can write VBS behind the scene's to error check. (Something you were wondering about Shadowfyr - Yes, it is possible). I have barely glanced at that though. This is my first time using Access. I haven't touched a database program since DBase IV, 15 years ago or so. (Ran under DOS).

Do you still feel this is a better method than the one I mentioned in my last post?

Thanks a ton for your assistance, Nick (and others). Much appreciated. :)

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Fri 13 Sep 2002 05:03 AM (UTC)  quote  ]
Message
Currently, all of my items are stored in an Excel spreadsheet. The one benefit to this, is that it visually looks very pretty.

I don't know how practical it is to write VBScript to both retrieve and create/modify data in a spreadsheet. I figured a database might be better. (MS Access, since I have it).

Naturally, the first step for me, is to get it all working right in Access. Later I will try and iteract with the database using MUSHclient scripts.

There are three main item types: Weapons, wearable/holdable items, and 'the rest'. I figured it would be sensible to put them all in ONE database, even though it would mean that some fields would be marked "Not applicable".

Eventually, it would be sweet to be able to use an alias to do an item search on pretty much any field.

A third option I considered, was just to provide a checkbox (Boolean) field for each damage type, and just check the ones that are appropriate. On the form, I might try and program it so that it would be impossible to have "Not applicable" checked while any damage type is checked. Shouldn't be too hard.

It's highly unlikely that any new damage types will ever be introduced. Even if they are, Access allows you to add a new field to an existing database, though it may take some hard drive thrashing time to get it done.

In respect to my original plan, I can see that I might have to abandon it, though I hate doing so without learning how to manage the problem. Part of the reason I took this project on was just to learn how to use Access. I still have a feeling there is a simple fix, but that no one seems to know what it is.

Anyway, with that proposition I just offered, I guess I now have three choices: Checkboxes, bit-map, or Nick's special lookup.

I'll mull it over a little while longer... see what you think of my idea, then maybe I'll take another stab at it soon.

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

Posted by Shadowfyr   USA  (1,774 posts)  [Biography] bio
Date Fri 13 Sep 2002 03:01 AM (UTC)  quote  ]
Message
Ok. That is nice. So you can test it in there. However I still stand by the statement that you end up having to produce the same result in vbscript, once you do have it working. It does not therefore benefit you to even try to do it inside Access itself, unless you really think you want to look at it when not inside mushclient. If all computers had two monitors and dual-head graphics cards, maybe it would be, since you could then drop Access on the second display, but for the purposes of using the database from mushclient on most computers, it is imho not necessarilly that helpful.

But that is just my personal opinion. ;)

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Fri 13 Sep 2002 01:58 AM (UTC)  quote  ]

Amended on Fri 13 Sep 2002 02:01 AM (UTC) by Nick Gammon

Message

Look, this is what I am talking about ...

Example of doing a form in Access

Near the bottom of the form is the sub-form which shows all records (any number) from the weapon/damage table. As you can see it is nice and visual, you can click on any one and delete it, or click on the new record symbol ">*" to add a new one. You just select them from the combo box. Nice and simple.

This example does not use any scripting.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Shadowfyr   USA  (1,774 posts)  [Biography] bio
Date Thu 12 Sep 2002 10:52 PM (UTC)  quote  ]

Amended on Thu 12 Sep 2002 10:53 PM (UTC) by Shadowfyr

Message
True Nick. I hadn't thought of using a single request, but then breaking it up like that would also tend to mean that you have to enter each record for the weapon's types seperately. Otherwise you are right back to 'will this form store all the values or only one?' problem he already has. Unless you can build a script in the form within Access, (paradox allows this, as does dBase, but where talking about an MS -we do it all for you, so it won't work right- product). lol Even if I had it installed I would probably not use it to design it as Magnum is doing, since I would have to rewrite most of the stuff the form does in vbscript anyway. And if that is the case, why do it the way Access would in the first place? ;)

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Thu 12 Sep 2002 10:01 PM (UTC)  quote  ]
Message
Quote:

It is also quite slow, since you have to ask the database for the weapon number, then ask it to look up each type assigned to the weapon and then finally ask it for each of the names for those retrieved types.


It's not that bad, as you get all those pieces of information in a single query (joining the tables) and thus only do one ODBC call, not three. Also, the database server should be caching frequently-accessed and small pieces of data, so the time needed to do those joins could be quite small.

The reason I suggested the third table is that Magnum was having trouble making a form that used the two tables, but basically had a many-to-many relationship which isn't supported in third-normal form with two tables, without mucking around. The third table does things the "correct" way (in database design) and thus can be implemented simply in an Access form.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Shadowfyr   USA  (1,774 posts)  [Biography] bio
Date Thu 12 Sep 2002 09:56 PM (UTC)  quote  ]

Amended on Thu 12 Sep 2002 09:57 PM (UTC) by Shadowfyr

Message
Well we are looking at this situation (and most muds would use something similar):

Weapon                Damage Type(s)
------------          ------------------
Zeldan's Flameblade   Heat, Edge, Magic

The solutions to this is one of the following:

Bit-flag method - Stores type in an unsigned integer where the types are:
  1 - Edged
  2 - Blunt
  4 - Pierce
  8 - Heat
 16 - Cold
 32 - Poison
 64 - Mind
128 - Magic
256 - Asphyxiation
512 - Acid
So The above weapon would be stored as "Zelden's Flameblade,137" and the actually types would be returned from an array in the script, where the element in the array is the 'bit position' used to store that type.

Two Tables - Also uses an array in the script, but would use the following:

Table 1: Weapons
Weapon                Weapon Number
------------          ------------------
Zeldan's Flameblade   1

Table 2: Types
Index to the Weapon   Damage Type
-------------------   ------------------
1                     3
1                     0
1                     7


You look up the weapon to get the number, then use the number to get the damage index and use it to look up the name in the array.

Three Tables - Pointless, unless you are actually using Access or the like and "can't" store the names in a faster array structure. It is also quite slow, since you have to ask the database for the weapon number, then ask it to look up each type assigned to the weapon and then finally ask it for each of the names for those retrieved types. This wastes a lot of time and is even worse when used from scripting, since ADODB access is twice as slow as the same look up performed by a compiled program through direct database API calls.

The first option is 'always' better, if you know that the thing you are going to look for won't change, even if you have to use a long integer to store all the possible combos. The second and third options are best left for if you don't know for certain how many types you have to worry about and even then, you are better off to use the third option to 'store' the names, but the second option to use them by loading the types into a global array (thus avoiding having to perform multiple ADODB searches each time for the names).

If I planned to do that I would use a OnPluginConnect sub to load all the types into a mushclient variable, padding them to equal lengths, then just multiply the type number by that length to get the name. Doing so would eliminate the time taken to look up each type when reading a record, while also avoid the hassle created by having to split the string into an array every time. If there where like 100+ types though, you wouldn't have much choice but the use the database. :p

Basically I agree that one table is always better, but it depends on how complex the situation is and your version assumes that a weapon only does one type of damage, which is not a good assumption to make. Even some types of normal swords can do slashing 'edge' attacks, blunt trauma and piercing damage. It just depends how you hit someone with it. ;)

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


13,114 views.

This is page 1, subject is 4 pages long: 1 2  3  4  [Next page]

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]