Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Killfile
Novice


Joined: 30 Sep 2002
Posts: 32
Location: USA

PostPosted: Wed Nov 13, 2002 4:17 pm   

Database Math
 
The mud I play on has a randomizer to change the hitpoints of the mobs in a room within a range computed by a forumla I don't have access to.

I'm trying to use the database to read in hitpoint values and generate an average hitpoints value for each mob record

Problem -- Once a value is in the database I don't seem to be able to write to IT in any way. I tried all the stuff in the help file, that doesn't seem to work. One note... I'd like to be able to do this with record.

My current statement, (which does not work) is

#MATH %rec.hp (%1 + %rec.hp*%rec.NumScaned)/(%rec.NumScaned + 1)

I tried the math part seperate, that is calculating correctly... so the problem is in assignment. What am I doing wrong. I'm sure I'm going to kick myself when I read it, but I'm out of ideas.


--Killfile
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Wed Nov 13, 2002 4:51 pm   
 
%rec is a system variable, you can't change it.

#DBPUT {} {hp} {%eval((%1 + %rec.hp*%rec.NumScaned)/(%rec.NumScaned + 1))}

LightBulb
Senior Member
Reply with quote
Killfile
Novice


Joined: 30 Sep 2002
Posts: 32
Location: USA

PostPosted: Wed Nov 13, 2002 5:14 pm   
 
No luck....

My current script reads as follows

#IF (%query( ((&Room = %roomnum( )) & (&Zone = %zonename( ))), ALL) = "") {
#ADDKEY NewMob HP %1
#SAY No Mobs Previously In This Room
} {
#query ((&Room = %roomnum())&(&Zone = %zonename())) {ALL} (1)
#VARIABLE NumScan %db( %rec, NumberScaned)
#SAY Updating Record. Cur HP Val is %rec.HP
#DBPUT {} {HP} {%eval((%1 + %rec.HP * %rec.NumberScaned)/(%rec.NumberScaned + 1))}
#SAY Record Updated. New HP Val is %rec.HP
#DBPUT {} {NumberScaned} {%eval(%rec.NumberScaned + 1)}
}

It executes, but no changes are made to the HP field. Note, the field names in this post are correct, the first was from memory, this is cut and paste.


--Killfile
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Wed Nov 13, 2002 7:20 pm   
 
From "Introduction to the Database", "Programming the Database", "Accessing Database Records", in the zMUD helpfiles.

(quote)
To set a specific record, use the #DBPUT command. The first parameter is the record number to save. If omitted, the data is stored to the current database record. The second argument is the database variable to be stored, or a list of keys and values to be changed. For example,

#DBPUT 20eq %dbget(21eq)
will store a copy of record 21 in the Equipment database on top of record 20. Actually, you can do the work of #DBPUT with #ADDKEY, but sometimes it is easier to read to use #DBPUT. For example, both of the following lines change the Name field of record 20 to Zugg:
#ADDKEY 20 Name Zugg
#DBPUT 20 Name Zugg
Actual database records also have an additional field name that is always present, called Num. Num returns the record number in the database with the two-character database name appended to it. So, in the above example, %db(,Num) would return 20eq

(endquote)

So, my best guess would be to provide a specific record number.

#DBPUT {%db(,Num)} {HP} {%eval((%1 + %rec.HP * %rec.NumberScaned)/(%rec.NumberScaned + 1))}

If it doesn't work, I'm sorry but I'm fresh out of ideas.


LightBulb
Senior Member
Reply with quote
Killfile
Novice


Joined: 30 Sep 2002
Posts: 32
Location: USA

PostPosted: Thu Nov 14, 2002 4:24 am   
 
I resolved the issue thanks in lage part to your advice lightbulb.

The solution is mostly what you have above in your last post with one addition...

I stored the record number to a variable using the %query function. Then dereferenced it in the #DBPUT command to supply the actual record number. Kaboom! It works....

Thanks for all your help.

--Killfile
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net