mIRC Home    About    Download    Register    News    Help

Print Thread
variables #210462 17/03/09 02:37 AM
Joined: Mar 2009
Posts: 4
S
silvaheyes Offline OP
Self-satisified door
OP Offline
Self-satisified door
S
Joined: Mar 2009
Posts: 4
I'm running into a small problem which is probably super easy to fix but my brain isn't quite functioning it seems.. I guess having a kid in the background who is whiney is the problem. lol

Anyway.. I need some help with variables. I have a command which works fine but here's what I want to add onto it.. The command is for a RP. When the person drinks it increases their health by 1, Certain people in the RP are pregnant and want a nursing command but since nursing is hard on a mother I wanted to make it decrease 1 health from the mother when nursed upon. I can't seem to get it right though.. The overall nursing command works but I can't seem to make it read who the mother is. In the variables I have %mother(nick of the person here) (mothers name here) How do I get it to read the mother's name from there and decrease her health by 1 which is under %(nick) (health) in the variables?

Re: variables [Re: silvaheyes] #210463 17/03/09 04:21 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Please show us the actual code you are using to set the variables so that I (or someone else) can provide you with actual code, rather than an educated guess.

Re: variables [Re: RusselB] #210464 17/03/09 04:40 AM
Joined: Mar 2009
Posts: 4
S
silvaheyes Offline OP
Self-satisified door
OP Offline
Self-satisified door
S
Joined: Mar 2009
Posts: 4
Sorry. smile

on *:TEXT:!nurse*:#:{
if (Pup isin %p [ $+ [ $nick ] ]) {
/set % $+ $nick $calc % [ $+ [ $nick ] ] + 1
/msg $chan 15,1 $+ $nick suckles from their mother, %mother [ $+ [ $nick ] ] $+ . $nick $+ 's HP is now % [ $+ [ $nick ] ] $+ . }

This code works.. But like I said, I want it to decrease the mother's health by 1.

Re: variables [Re: silvaheyes] #210470 17/03/09 02:36 PM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Where is the variable that contains the mother's health?

Re: variables [Re: RusselB] #210471 17/03/09 03:25 PM
Joined: Mar 2009
Posts: 4
S
silvaheyes Offline OP
Self-satisified door
OP Offline
Self-satisified door
S
Joined: Mar 2009
Posts: 4
The var for the mother's health is %(their nick here) (health) in the variables. It's not in the code because I couldn't make it work. :P

Last edited by silvaheyes; 17/03/09 03:27 PM.
Re: variables [Re: silvaheyes] #210480 17/03/09 10:08 PM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
This re-write changes the method of evaluation of the dynamic variables simply due to the fact that I have a hard time working with dynamic variables using the method that you have used (which is also the method shown in the help file).
Code:
on *:TEXT:!nurse*:#:{
  if (Pup isin $($+(%,p,$nick),2)) {
    inc $+(%,$nick)
    msg $chan 15,1 $+ $nick suckles from their mother, $($+(%,mother,$nick),2) $+ . $nick $+ 's HP is now $($+(%,$nick),2) $+ .
    dec $+(%,$($+(%,mother,$nick),2))
    msg $chan 15,1 $+ $($+(%,mother,$nick),2) now has $($+(%,$($+(%,mother,$nick),2)),2) HP available for her pups.
  }
}


Re: variables [Re: RusselB] #210483 17/03/09 10:22 PM
Joined: Mar 2009
Posts: 4
S
silvaheyes Offline OP
Self-satisified door
OP Offline
Self-satisified door
S
Joined: Mar 2009
Posts: 4
Thanks! It works nicely. smile

Re: variables [Re: silvaheyes] #210486 17/03/09 11:20 PM
Joined: Feb 2005
Posts: 342
R
Rand Offline
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Just as a side note, and something to take into consideration.

Some people tend to use:
$($+(%,staticVarName,.,$identifier),2)

Other people just use:
%staticVarName. [ $+ [ $identifier ] ]

Personally, I prefer the brackets, because I like the seperation in code. (Atleast while using variables)


The other option is to use Hash Tables. (You have to save (/hsave) before you exit mIRC, and load (/hload) them after you start mIRC.) Hash Tables are extremely useful, and are often a lot cleaner for this sort of thing.

Example:

hadd -m HealthPoints $nick 100

$hget(HealthPoints,$nick) would return "100"

hinc HealthPoints $nick

Would increase that number by 1 (so it'd be 101 if you checked it).

Hash tables generally allow you to handle it a little more cleanly, for example you could have a table "Game1" and various stats stored for each nick.

Code:
var %table = Game1 , %health = $+(Health.,$nick) , %mana = $+(Mana.,$nick)

; User uses a potion to restore..
; health by a random value between 200 and 250
; mana by a random value between 100 and 125

hinc %table %health $r(200,250)
hinc %table %mana $r(100,125)

msg $chan $nick currently has $hget(%table,%health) health and $hget(%table,%mana) mana.