Tremulous Forum

General => Troubleshooting => Topic started by: OhaiReapd on May 10, 2011, 12:27:56 pm

Title: If statements got me down, bro!
Post by: OhaiReapd on May 10, 2011, 12:27:56 pm
Code: [Select]
alias g0 say_team I am a ^7Granger ^5with^7 \$$p_hp\ ^5Health and ^7 \$$p_credits\ ^5Evos.
alias g1 say_team I am an ^7Advanced Granger ^5with^7 \$$p_hp\ ^5Health and ^7 \$$p_credits\ ^5Evos.
alias g2 say_team I am a ^7Dretch ^5with^7 \$$p_hp\ ^5Health and ^7 \$$p_credits\ ^5Evos.

alias c1 "if class = builderupg g1 c2"
alias c2 "if class = level0 g2 c3"

bind CTRL "if class = builder g0 c1"

alias ass say_team fucknuts
bind ALT "if class = builder ass g2"

This is code that I have written for binds that should exec depending on what class I am. However, its not working. I have spent like 3 hours on this trying to get it to work. Please help.

Thanks,
Reapd
Title: Re: If statements got me down, bro!
Post by: Celestial_Rage on May 10, 2011, 06:19:55 pm
I don't think the if statement can equate strings. If the strcmp command is built in, you can use that, or replace all the names with numbers.
Title: Re: If statements got me down, bro!
Post by: UniqPhoeniX on May 10, 2011, 08:01:26 pm
class is a cmd not a variable... but in case your client is modded and has such a cvar, you'd prob need to use "strcmp \$class\ = builder cmd_if_true cmd_if_false" etc
Title: Re: If statements got me down, bro!
Post by: OhaiReapd on May 10, 2011, 08:51:03 pm
If I type /strcmp in console, it will explain it, but when I bind it, I get a unknown cmd. :/

Here, menace gave me this. Doesn't work tho. Lets work on this.


Code: [Select]
seta hp "p_hp"
seta heal "itemact medkit; say_team ^1***^7[ ^5>>^3Need backup! ^7| ^3I only have ^1>>^7\$$p_hp\^1<<^3 Health!^5<< ^7]^1***"
seta noheal "echo ^5Health is fine. Dumbshit....."
bind e "if hp < 90 heal noheal; deconstruct; +button3;-button3"

I added the say_team. But it execs. However, it only execs heal. So even with 100 health, it will say it and would activate medkit... >:(
Title: Re: If statements got me down, bro!
Post by: F50 on May 11, 2011, 08:02:49 am
The problem is with

Code: [Select]
seta hp "p_hp"
which only ever gets executed once, so hp will be the same, regardless of what your health is.
Title: Re: If statements got me down, bro!
Post by: David on May 11, 2011, 11:09:35 am
hp will be set to the string p_hp, not the value of p_hp.
Turning "p_hp" into a number will always be 0, because it's not a number.
Title: Re: If statements got me down, bro!
Post by: OhaiReapd on May 11, 2011, 12:45:09 pm
So, how would I fix it? :[ This is so confusing..... Thanks for the help so far!!!
Title: Re: If statements got me down, bro!
Post by: Menace13 on May 11, 2011, 11:56:38 pm
http://www.tremfusion.net/wiki/Features_list#The_.60if.60_command

I believe it's the same in FSM-GPP.
Title: Re: If statements got me down, bro!
Post by: OhaiReapd on May 12, 2011, 12:23:15 am
http://www.tremfusion.net/wiki/Features_list#The_.60if.60_command

I believe it's the same in FSM-GPP.

but that's not a tutorial. It barely explains it. >:(