ID:149759
 
in my rabdom battle code i get 2 errors that rand is an udefined proc and an invalid expression error. i have thouroughly looked through it and am continually frustrated, because i see nothing wrong with it. this is what some of my code that deals with my random battle system looks like:

mob/var/location //this var records the players location
mob/Move()
..()
var/encounter=rand(1,10) //this decides whether there will be a battle
if(encounter==10)
encounter=rand(1,2) //this decides what monster will appear, and this is line 454
if(usr.location=="valley") //this is line 455
if(encounter==1)
new/mob/monster/wild_animal(locate(x,y+1,z))
if(encounter==2)
new/mob/monster/goblin(locate(x,y+1,z))
if(usr.location=="dragon_lair")
encounter=rand(1,5) //this is line 476
if(encounter<=4)
new/mob/monster/Dragon_Pup(locate(x,y+1,z))
if(encounter==5)
new/mob/monster/Dragon(locate(x,y+1,z))

area/map_locations
valley_domain
Entered()
usr.location="valley"

my errors/warnings look like this:

454:error:rand:undefined proc
476:error:rand:undefined proc
455:error::invalid expression

if u can tell me what is wrong with that it would be much appreciated
You can't set a var to rand() at runtime, only at compile time, also your best bet for random combat would be the prob() proc.
I don't actually see any trouble with rand(), although you're using usr in some bad places. None of the code you showed should include usr at all.

Within Move(), src is the mob in question, so you should always use src instead of usr there. Entered() takes an atom/movable as an argument, so you should use that in place of usr:
area/valley
Entered(atom/movable/A)
if(istype(A,/mob))
var/mob/M=A
M.location="valley"

One other big thing: In mob.Move() you shouldn't call any monster spawn code unless the mob is a player, since your monsters are also mobs.

You can actually bypass that kind of code anyway by using, in Move(), loc.loc.name instead of src.location. If src.loc is a turf (you can always double-check this with isturf(), then loc.loc is an area, and you can check its name. Or, better yet, you could put the monster spawn code in the area and call that.
area
var/encounter_prob=10 // 10% chance of a monster
var/list/monsters

proc/Encounter(mob/player)
if(!prob(encounter_prob)) return
// this use of pick() doesn't work in version 306
var/mon=pick(monsters)
new mon(locate(player.x,player.y+1,player.z))

area/valley
monsters=list(/mob/monster/wild_animal,/mob/monster/goblin)

Lummox JR
In response to Nadrew
Nadrew wrote:
You can't set a var to rand() at runtime, only at compile time

Um... you got that backwards. rand() is a runtime proc, not compile time.

Lummox JR
In response to Lummox JR
Oops, I was thinking that when I wrote that too..