ID:139501
 
Code:mob
var
Level = 1
HP = 100
str = 5
dex = 5
stam = 5
luck = 5
armr = 1
wep = 1
atk = (str + (dex/2) + wep) * 2 //This line causes compilation problems



Problem description: I want to determine a variable with an equation that uses other variables in it. The equation is for the variable Atk. Here is the equation: Atk = (str+(dex/2)+wep)*2 and then I can determine damage with this. Damage = (Atk*level+(level/2)-def)(x) where x is a random number from 0.5 to 1.2... I have been trying to plug this equation into a simple mob var but it doesn't seem to work. any ideas?

You cannot at compile-time set a variable to some non-constant expression. What you need to do is instead either update the variable whenever you change one of the dependent variables, or just use a function that calculates it on the spot for you whenever you need it.
In response to Garthor
That's what I am trying to do with the equation, I want it to calculate the variable on the spot so that if the player improves their stats, then the equation will be updated due to their stats, simple algebra, but I still don't understand how to plug it in.
If you had read what garthor had said carefully, you would not have posted what you did.

Garthor is saying that you cannot use other variables, which can change, to define a value for a variable at start-up. Instead, you have to use a proc that updates this value during run-time.

So...

mob/var
//... the other stuff that doesnt get involved with atk
str = 5
dex = 5
wep = 1
atk = 17 //from the values you gave.
mob/proc
UpdateAttack()
att = (str + (dex / 2) + wep) * 2

mob/verb/LevelUp()
str += 2
dex += 1
//...etc
UpdateAttack()

mob/verb/EquipWeapon(obj/weapon/O)
wep = O.power
UpdateAttack()


Please note the two verbs are just examples.

With the UpdateAttack() proc in place, all you need to do is call it whenever any of the 3 affecting variables are changed.
In response to SadKat Gaming
Ok, I figured out my own way of doing it. Basically I made a proc that determines the value with the equation. Etc. Etc. Now I have two new problems. 1) my randomizer in the code
              Attack(mob/M as mob in oview(1))
                                                oview() << "[usr] attacks [M]!"
                                                var/atk = (str+(dex/2)+wep)*2
                                                var/x = rand(0.5,1.2)
                                                var/damage = (atk + (Level/2)-def) * x
                                                world << "[damage] damage!"
                                                M.HP -= damage
                                                M.DeathCheck()



Isn't working, it either comes out 0, or 25.5 assuming that my variables are str = 5, dex = 5, wep = 5, level = 1, and def = 0. so basically the randomizer isn't being determined and multiplied at all.

2) For some reason when I use the attack verb, I can kill my turf. Example, I am destroying my grass. Any Ideas?
In response to Humansftw
rand() will only give you integers. You need to instead do rand(5,12)/10.
In response to Garthor
Garthor wrote:
rand() will only give you integers.

If you call as it you've written (i.e., omit the range) then it actually gives you a decimal number from 0 to 1.
In response to Kaioken
Thank you everyone for the help, you all helped a lot, and I'm glad this community is so quick about it too lol.