ID:2035016
 
Code:Using Stats to determine what Magic you get.
if(usr.Attack>usr.MMana||Defence)
switch(pick("Fire","Ice"))
if("Fire")
return
if("Ice")
return
if(usr.MMana>=usr.Attack||usr.MMana>=usr.Defence)
switch(pick("Poison"))
if("Poison")
usr.Poison=1
src.Magic_Type= "Poison"
return
if(usr.Mana>Attack||usr.MMana)
switch(pick("Earth","Heal"))
if("Earth")
return
if("Heal")
return


Problem description: As the title states I am trying to make it so that you are able to gain magic based on your highest stat.I thought the way I did it was completely right, but it is not working at all. I made sure to have my mana stat higher than both attack and defense yet I am not able to gain the magic type "Poison". Is there something I am missing?

if(src.Attack > src.MMana)
//...
return
if(src.Mana > src.Attack)
//...
return


using || makes the if statement true if either side is not null or 0.

I also don't know if you know but pick("Fire","Ice") will choose one at random, and if you're going to do it that way I would suggest doing something such as

switch(rand(0,1))
if(0) // Fire
if(1) // Ice
else
return // neither
Yeah I was going for random, but didn't know if using pick or rand would be better. But what about the stat "Defense", Where would I put that
First, as long as 'Defence' is not 0 or null, then the first if statement will always be true. Try this logic out:
if(usr.Attack > usr.MMana || usr.Attack > usr.Defense)


Secondly, what's happening inside the block is a little confusing, why are you returning if fire or ice is picked? Why not just return without picking them, since they are the only results, and you seem to be doing nothing with what you pick.
So I got it to sorta work, but how do I make it so that it doesn't go to the wrong category? Like they have more mana then all other stats, but since it has if(usr.Attack > usr. Defense) before if(usr.Mana> usr.Attack) and their attack is indeed greater than their defense how would I stop it from giving them a attack based magic type?
In response to Dayvon64
I thought about it and if you're using < and/or > there will be a third option for if they're equal that won't do anything you'll need to modify yours or add in another option >= and/or <=
This snippet shows one way I'd probably do what you want to do:

#define STAT_ATTACK "attack"
#define STAT_DEFENSE "defense"
#define STAT_MANA "mana"

mob/player
var list/stats = list(STAT_ATTACK = 5, STAT_DEFENSE = 5, STAT_MANA = 5)

// returns the name of the highest stat
proc/get_highest_stat()
// returns 'attack' as the highest by default
. = STAT_ATTACK

for(var/stat in stats)
// if the stat 'stat' is greater in value than the current
// value set to return, overwrite it with the larger value 'stat'
if(stats[.] < stats[stat])
. = stat

proc/determine_magic()
switch(get_highest_stat())
if(STAT_ATTACK)
// attack is the highest stat; do stuff...

if(STAT_DEFENSE)
// defense is the highest stat; do stuff...

if(STAT_MANA)
// mana is the highest stat; do stuff...


The issue with how you're doing it, is you are assuming a stat is the greatest in value, only after comparing it to one other stat. So mana could be the highest stat, but since you stop checking after the mob's attack comes back higher than their defense, they get an attack-based magic type instead of a mana-based (as they should).

My snippet gets the highest stat via get_highest_stat(), and the determine_magic() proc evaluates the return value [of get_highest_stat()] and does what it needs to do.
I tried to try what you did, but it kept saying that it was an unidentified proc when I call it.
In response to Dayvon64
Post your code.
In response to FKI
I didn't see you call any procs?
switch(get_highest_stat())

In determine_magic().
In response to FKI
Oh gg I didn't even see that, but looked through it nothing seemed out o the ordinary so I can assume Davyon just copied paste and edited.