ID:263128
 
Yeah, it's a long line of code, but I keep getting an "undefined operation" error on this line and can't find anything wrong with it.
Code:
var/total = (((src.paintball_game_stats["enemy_kills"]*500) + (src.paintball_game_stats["enemy_hits"]*100) + (round(src.paintball_game_stats["shots_hit"]/src.paintball_game_stats["shots_fired"],0.01)*1000)) - ((src.paintball_game_stats["friendly_kills"]*500) + (src.paintball_game_stats["friendly_hits"]*100) + (src.paintball_game_stats["killed_by_enemy"]*275) + (src.paintball_game_stats["taken_enemy_hits"]*50)))
Totally unrelated: If you insert \ at the end of a line, you can continue the same "line" of code on the next line and it will compile just fine.

var/text = "If you\
want to do\
something like this\
for example"

var/formula = A\
+B\
-C\
*INFINITY


Related: [link]
In response to Foomer
Ah, I didn't think that applied to anything but text strings. I'll keep that in mind.
In response to Mobius Evalon
Is that a global variable? Seems like it is. o.o;;
You can only have, for instance
mob/var/hp=src.maxhp
at runtime. Not in compile-tile.
In response to Mysame
You can't assume that it's global, and chances are it's not. Mobius has been programming for just a tad bit, but I think he understands that much.

Mobius: I'd say it has something to do with Division by 0, but I'm not sure if it has an error specifically for that or what.
In response to Audeuro
I know Mobius is a good coder, but it works fine when I try to compile it, funnily enough.
I believe you'll find the problem is that some of the values in your associative list were never set, so they're evaluating to null. If you try to use something like null*500, DM will freak.

You might be better off loading these values into local vars before calculating with them. I.e.:
var/ek = paintball_game_stats["enemy_kills"] || 0
var/eh = paintball_game_stats["enemy_hits"] || 0
var/sh = paintball_game_stats["shots_hit"] || 0
// this one is used in division, so we must force it to 1 instead of 0
var/sf = paintball_game_stats["shots_fired"] || 1
var/fk = paintball_game_stats["friendly_kills"] || 0
var/fh = paintball_game_stats["friendly_hits"] || 0
var/kbe = paintball_game_stats["killed_by_enemy"] || 0
var/teh = paintball_game_stats["taken_enemy_hits"] || 0


You'll also find that you don't need nearly as many of those parentheses as you have. Multiplication and addition trump addition and subtraction every time. You also don't need src in there so much because it's implied. While sometimes a little clarity never hurts, here it's actually a detriment because it's making a long line even longer.

var/total = ek*500 + eh*100 + round(sh*1000/sf,10) - fk*500 - fe*100 - kbe*275 - teh*50


Also, notice how I changed your round() statement. Floating point has problems with numbers like 0.1 because it can't represent a fraction 1/10 without repeating digits in binary. Rounding to 0.01 will get you an imperfect result, and then mulitplying by 1000 just multiplies the error. Multiplying by 1000 first, and rounding to 10 (10=0.01*1000) will completely eliminate that error. I also multipled by 1000 before the division, which further decreases any chance of rounding error in the division that could throw off the results.

Lummox JR
In response to Lummox JR
(Yeah, I know this response is four months after the fact, I didn't check this thread again until just now.)

Wow. Just when I think I know what I'm doing, Lummox comes along and proves me wrong. =D

Many thanks, Lummox. You have expanded my knowledge even further.