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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
adamandkate
Wanderer


Joined: 14 Oct 2009
Posts: 57

PostPosted: Mon Nov 14, 2011 9:42 pm   

[Solved] char.vitals.hp inside an @var
 
#var health %gmcp.Char.Vitals.hp
#if ((@first) and (@second > 100) and (@health < 1550)) {
do this
}

In this situation the gmcp sets the variable to @health = 1900 but it still fires everytime when it shouldnt.

#var health 1900
#if ((@first) and (@second > 100) and (@health < 1550)) {
do this
}

However, in the above it correctly does not fire.


Last edited by adamandkate on Tue Nov 15, 2011 8:48 pm; edited 1 time in total
Reply with quote
hadar
Apprentice


Joined: 30 Aug 2009
Posts: 198
Location: my apt, in california

PostPosted: Tue Nov 15, 2011 2:00 am   
 
whats the full script? you are showing bits and peices something else could be causing it to misfire
_________________
if you build it they will come, assuming that they have not already come to build it
Aardwolf Bootcamp
My youtube channel
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Tue Nov 15, 2011 6:20 am   
 
The problem looks to be in your usage of the #VARIABLE command. The correct usage in this case would be
Code:
#var health (%gmcp.Char.Vitals.hp)
#if ((@first) and (@second > 100) and (@health < 1550)) {
do this
}
The use of parenthesis tells CMud to evaluate the contained portion before assigning it to the variable. Without those CMud has to guess what you want and the best guess that was possible from the string provided was a literal text string. The comparison in your #IF was seeing ("%" < "1") as true. This is a correct behavior.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
adamandkate
Wanderer


Joined: 14 Oct 2009
Posts: 57

PostPosted: Tue Nov 15, 2011 11:36 am   
 
heres the full code. still cant quite get it to work
#var health {%gmcp.Char.Vitals.hp}
#var maxhealth {%gmcp.Char.Vitals.maxhp}
#math percenthealth 100*@health/(@maxhealth)
#if ((@canoverdrive) and (@adrenaline > 100) and (@health < 33101)) {
#var canoverdrive 0
od
}

in this situation canoverdrive =1. adrenaline = 500. health = 100

any ideas. thanks
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2307

PostPosted: Tue Nov 15, 2011 2:21 pm   
 
You didn't look closely at Vijilante's code. He said to use parentheses, not curly braces. In addition, you don't need #MATH if you are using parentheses. The first part of your code should be:
Code:

#var health (%gmcp.Char.Vitals.hp)
#var maxhealth (%gmcp.Char.Vitals.maxhp)
#var percenthealth (100*@health/(@maxhealth))
Reply with quote
adamandkate
Wanderer


Joined: 14 Oct 2009
Posts: 57

PostPosted: Tue Nov 15, 2011 3:50 pm   
 
ooooh whoops. thanks!

all working good now. appreciate the help
Reply with quote
adamandkate
Wanderer


Joined: 14 Oct 2009
Posts: 57

PostPosted: Tue Nov 15, 2011 4:06 pm   
 
while were on the topic. is that percent variable correct? it seems to report 100 as the answer regardless of the variables
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Tue Nov 15, 2011 4:22 pm   
 
If both @health and @maxhealth are integers, then CMUD will do integer division (no decimal). For CMUD to do floating point division, you'll need to convert at least one of them into a floating point number, using the %float function.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 3964
Location: Pensacola, FL, USA

PostPosted: Tue Nov 15, 2011 6:29 pm   
 
or just use 100.0, there is no need for nested parenthesis on @percenthealth's equation
_________________
Discord: Shalimar#3679
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2307

PostPosted: Tue Nov 15, 2011 9:28 pm   
 
Adamandkate--the %gmcp predefined variable only works on muds that implement GMCP, which is essentially mud data encoded into the output stream, similar in concept to MXP. Cmud will automatically grab that data and populate the %gmcp values.
Reply with quote
danedwards2
Newbie


Joined: 16 Nov 2011
Posts: 1
Location: Chicago, Illinois

PostPosted: Wed Nov 16, 2011 9:22 am   
 
this thread helped me solve my problem. thanks. Smile
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Wed Nov 16, 2011 11:30 am   
 
another spammer, wtf?
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2307

PostPosted: Wed Nov 16, 2011 1:57 pm   
 
Bleh. Ignore my response above, I was misreading the question.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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