ID:261890
 
Red_Warrior
icon = 'troops.dmi'
icon_state = "p1w"
var
ATK=3
RNG=1
AC=9
W=1
type2 = "troop"
Click(mob/a)
if(player2==usr.key)
return
if(turn==1)
switch(alert("Issue an Order","Which order do you want to issue?","Move","Attack","Cancel"))
if("Move")
var/select=input("What direction?","Choose a direction.") in list ("North","South","East","West")
if(select=="North")
for(var/mob/o in world)if(o==src)step(o,NORTH)
Turn()
if(select=="South")
for(var/mob/o in world)if(o==src)step(o,SOUTH)
Turn()
if(select=="East")
for(var/mob/o in world)if(o==src)step(o,EAST)
Turn()
if(select=="West")
for(var/mob/o in world)if(o==src)step(o,WEST)
Turn()
if("Attack")
for(var/mob/m in oview(1)) if(type2=="troop")
usr << "[m] and [src]."
if(m.Owner==1)
usr << "You can't attack that."
return
world << "[src] attacks [m]!"
var/roll = rand(1,20)
world << "[src] rolls a [roll]."
roll = roll + src.ATK
if(roll<=m:AC)
world << "[src] misses."
Turn()
world << "[src] hits [m], and inflicts one wound."
m:W--
if(m:W==0)
m:Death()
Turn()

The problem here is that the troop will move just fine, however... It won't attack other troops in its oview, it'll only attack invisible usrs. Help?
Devourer Of Souls wrote:
The problem here is that the troop will move just fine, however... It won't attack other troops in its oview, it'll only attack invisible usrs. Help?

No use colon operator. Ungh.

No conflate usr with player. Ungh!

Lummox JR
The problem originates after you start the for(loop). The next line, (actually the same line, although you should put that if() statement on the next line) you're checking to see if(type2 == "troop")... this means, since you don't have a focus (src.type2, usr.type2, m.type2), it's checking src, as src is always the default. I think you want to check m.type2, instead. Also, you keep using src in this statement. Don't use src here. In the Click() proc, src defaults to what you are clicking on. Usr is YOU, the person who is clicking on things. Usr and src are very tricky, so before you do anything, you need to open a new BYONDscape window, and find Lummox JR's document on usr and src. I'm pretty sure it doesn't require a subscription. Read that, then fix the necessary things. Also, use periods instead of colons as your focus.


~Polatrite~
In response to Polatrite (#2)
I'm not sure he's making a mistake with using src... I think the idea is he's issuing orders to the mob that's clicked on and that mob carries them out.

I think the problem is the opposite... using usr instead of src:

in oview(1)

If you just put "oview(1)", it will grab everything within one square of the usr, not the src. oview(1,src)... so he's clicking on the trooper, telling it to attack, and it's looking for a mob within one square of the clicker rather than the clickee.

Here's another tip for Devourer... all those vars you defined for Red Warrior... um... every mob in your game that has range and attack and so forth, are they all gonna be Red Warriors? If not, then you shouldn't be declaring them like that, you should declare them (without any value, or with a default value that most mobs will have) under mob, and then define them = whatever in Red Warrior.

mob
var
grossnationalproduct
Red_Warrior
grossnationalproduct = "grizzle"
In response to Lummox JR (#1)
You know, that's just as annoying as the things you gripe about. How about setting a maturity example here instead of grunting "usr bad! No use usr!" all the time. You're just slamming down a trite comment, and giving no explanation as to why. A simple link to your article would go a lot furthur in getting people to understand why. This is border-line flame material, if you ask me. Please stop.

~X
In response to Lummox JR (#1)
Lummox, the problem is that it IS attacking usrs.

oview(), by default, takes usr as an argument. What you can do it use something similar to oview(1,src).
In response to Jon88 (#5)
Lummox, the problem is that it IS attacking usrs.

No, it isn't.

This is what Lummox means when he says "no conflate usr with player." The "usr" is the cliented mob that triggers the proc, and since usr will never be found in oview(1,usr), whatever it's attacking is categorically not the usr.

It may be another player's invisible mob that's within one square of the player controlling the mob... but those mobs are not usrs. There isn't even a plural of "usr"... at any given moment, only one mob is properly called "usr".

It's this misunderstanding that leads inexperienced coders to wonder why they can't refer to "the player" in the middle of a non-verb procedure by using usr and have the computer know exactly which mob they're talking about.
In response to Hedgemistress (#6)
Thanks everybody :P
In response to Devourer Of Souls (#7)
You're welcome.
In response to Xooxer (#4)
Xooxer wrote:
You know, that's just as annoying as the things you gripe about. How about setting a maturity example here instead of grunting "usr bad! No use usr!" all the time. You're just slamming down a trite comment, and giving no explanation as to why. A simple link to your article would go a lot furthur in getting people to understand why. This is border-line flame material, if you ask me. Please stop.

Linking to the article every time would be easy if it was a short URL and I knew it by heart, which it isn't. But the comments here are mostly not the usual one, which is covered in the article. In this case I'm on about the conflation of usr with "the user" as in "the player", about which I've spoken so many times that saying any more would be ridiculously redundant. I shouldn't have to go through the same long explanation every time, and I'm not prepared to write another article. Bottom line is, a big production isn't required, and a terse response suffices.

Lummox JR
In response to Lummox JR (#9)
Lummox JR wrote:
Linking to the article every time would be easy if it was a short URL and I knew it by heart, which it isn't.

I used to keep a text file full of common stuff like that so I could just copy and paste things. Then I put a shortcut to it in the root of the Start menu. Quite handy. =)
In response to Crispy (#10)
Crispy wrote:
Lummox JR wrote:
Linking to the article every time would be easy if it was a short URL and I knew it by heart, which it isn't.

I used to keep a text file full of common stuff like that so I could just copy and paste things. Then I put a shortcut to it in the root of the Start menu. Quite handy. =)

Furthermore, throw a shortcut to the textfile in a toolbar on your start menu. Easy as a lightswitch.
In response to Lummox JR (#9)
If you have nothing nice to say...

~X