ID:141427
 
Code:
mob/proc

Initiate_Battle(mob/monster) //monster is the type of monster generated when entering turf
var/list/mob/order = new /list(rand(1,3) + 1) //turn order for battle
var/list/mob/monsters = new /list(order.len - 1) //list of monsters, used to choose which monster to attack

usr<<"[order.len]" //lets me know how many monsters are supposed to spawn
Create_Order(monsters,order,src,monster)
Test_Order(order) //lets me know the order to see if everything was added correctly


Create_Order(list/mob/monsters,list/mob/order,mob/player,mob/monster)
if(player.haste > monster.haste) //if player has higher haste
order += player //put him at the tope of the order
Add_Mons(monsters,order,monster) //add monsters to list
if(player.haste == monster.haste) //if equal haste
if(prob(50)) //50/50 who goes first
order += player
//Add_Mons(monsters,order,monster)
else
//Add_Mons(monsters,order,monster)
order += player
else
//Add_Mons(monsters,order,monster)
order += player


Add_Mons(var/list/monsters,var/list/order,var/mob/monster)
for(var/x = 1, x < order.len-1, x++) //while x < the length of the string - 1(minus one because one spot is reserved for player)
var/mob/y = monster //make a temp var that is the same as the monster type spawned
y.loc = locate(23,21-y,4) //assign location of monster
order += y //add monsters to order
monsters += y //add monsters to target list





Test_Order(var/tmp/list/Order)
var/tmp/mob/x
for(var/y = 1,y <= Order.len, y++)
x = Order[y]
usr<<"[y][x.name]"



/*********************************************************
*****************I tried a new way************************
*********************************************************/

mob/proc

Initiate_Battle(level) //monster is the type of monster generated when entering turf
var/list/mob/order = new /list(rand(1,3) + 1) //turn order for battle
var/list/mob/monsters = new /list(order.len - 1) //list of monsters, used to choose which monster to attack

usr<<"[order.len]" //lets me know how many monsters are supposed to spawn
AssignMon(monsters,level) // level is the monster's level group, its defined when the turf is entered
Test_Mons(monsters)
Test_Order(order) //lets me know the order to see if everything was added correctly
Create_Order(monsters,order,src)



Create_Order(list/mob/monsters,list/mob/order,mob/player)
var/mob/monster = monsters[1]
if(player.haste > monster.haste) //if player has higher haste
order = monsters.Copy(1,0)
order.Insert(1,player)
if(player.haste == monster.haste) //if equal haste
if(prob(50)) //50/50 who goes first
order = monsters.Copy(1,0)
order.Insert(1,player)
else
order = monsters.Copy(1,0)
order += player
else
order = monsters.Copy(1,0)
order += player


AssignMon(list/mob/monsters,level)
switch(level)
if("level1")
var/choice = rand(1,10)
if(choice >= 1 && choice <= 4)
for(var/x = 1, x < monsters.len, x++)
var/mob/y = new /mob/Monsters/Level1/Red_Slime
y.loc = locate(23,21-y,4)
monsters += y
if(choice >=5 && choice <= 8)
for(var/x = 1, x < monsters.len, x++)
var/mob/y = new /mob/Monsters/Level1/Goblin
y.loc = locate(23,21-y,4)
monsters += y
else
for(var/x = 1, x < monsters.len, x++)
var/mob/y = new /mob/Monsters/Level1/White_Tiger
y.loc = locate(23,21-y,4)
monsters += y


Problem description:

I'm trying to make a turn based battle system. I base it on the haste of the two mobs. I keep getting a run time error caused by Add_Mon(). I'm not sure how to correct it, please help.
var/mob/y = monster //wrong

Making a new mob and giving it the type path /monster (as opposed to /mob/monster) is probably not the way to go about making a new monster - And it may help to actually use the word new() somewhere, at that.

The correct way to do it:
var/mob/monster/y = new
//OR
var/mob/y = new/mob/monster
//Both of these will create a new monster. I don't think there's a difference between them- the bottom one is what you
//were trying to do, but the top one is better practice.

;)

PS. In future, it would be more helpful if you could show us the runtime error you got (ie. copy + paste it) so that the people helping you can see any useful information about it that you might have left out in your post.
In response to Adam753
Let me explain further, the monster var is an actual mob, i'm using it as var/mob/y = monster to make a variable identical to the monster var. Can the copy proc be used?


Here's the runtime:

runtime error: type mismatch: 21 - Red Slime (/mob/Monsters/Red_Slime)
proc name: Add Mons (/mob/proc/Add_Mons)
usr: the test (/mob)
src: the test (/mob)
call stack:
the test (/mob): Add Mons(/list (/list), /list (/list), Red Slime (/mob/Monsters/Red_Slime))
the test (/mob): Create Order(/list (/list), /list (/list), the test (/mob), Red Slime (/mob/Monsters/Red_Slime))
the test (/mob): Initiate Battle(Red Slime (/mob/Monsters/Red_Slime))
Level1 (274,252,1) (/turf/CombatGrass/Level1): Entered(the test (/mob), Level1 (275,252,1) (/turf/CombatGrass/Level1))
runtime error: type mismatch: 21 - Red Slime (/mob/Monsters/Red_Slime)
proc name: Add Mons (/mob/proc/Add_Mons)
usr: the test (/mob)
src: the test (/mob)
call stack:
the test (/mob): Add Mons(/list (/list), /list (/list), Red Slime (/mob/Monsters/Red_Slime))
the test (/mob): Create Order(/list (/list), /list (/list), the test (/mob), Red Slime (/mob/Monsters/Red_Slime))
the test (/mob): Initiate Battle(Red Slime (/mob/Monsters/Red_Slime))
Level1 (274,252,1) (/turf/CombatGrass/Level1): Entered(the test (/mob), Level1 (275,252,1) (/turf/CombatGrass/Level1))
runtime error: Cannot read null.name
proc name: Test Order (/mob/proc/Test_Order)
usr: the test (/mob)
src: the test (/mob)
call stack:
the test (/mob): Test Order(/list (/list))
the test (/mob): Initiate Battle(Red Slime (/mob/Monsters/Red_Slime))
Level1 (274,252,1) (/turf/CombatGrass/Level1): Entered(the test (/mob), Level1 (275,252,1) (/turf/CombatGrass/Level1))
In response to Sgbarnes91683
Ahh... I see... I'm starting to understnad now.
When you call Initiate_battle(), what do you put as the arg?

Actually, scratch that, after a few tests I know exactly what is wrong. It seems I was right for the wrong reasons! The problem is indeed caused by this line of code:
var/mob/y = monster

And as I also mentioned in my first post, it may help you to use the word "new" at some point here. It's hard to describe what this line of code achieves, but basically it creates a mob that is "empty". It doesn't have a physical form, it doesn't exist as such, but it's there and it's called Y. But, because Y doesn't exist in the map yet, trying to change it's variables will result in a runtime error! So the solution is simple: How can we make Y exist?
Easy, like this:
var/mob/y = new/monster

See? Told you that line needed the word "new" in it.
In response to Adam753
I wish it worked. c'est la vie. i'm at a loss now i've tried several different ways, and can't figure this out. I'm sure its simple
In response to Sgbarnes91683
First, in dream maker go to Build / Preferences and check generate debugging information. This will tell us exactly what line is causing the error. If you can't figure it out once it tells you which line it is come back on the forums and let us know.
In response to AJX
I tried a new method, which to me made more sense and got this runtime error, the new code is below the original code in the original message

runtime error: type mismatch: 21 - White Tiger (/mob/Monsters/Level1/White_Tiger)
proc name: AssignMon (/mob/proc/AssignMon)
source file: BattlePrep.dm,99
usr: the test (/mob)
src: the test (/mob)
call stack:
the test (/mob): AssignMon(/list (/list), "level1")
the test (/mob): Initiate Battle("level1")
Level1 (275,252,1) (/turf/CombatGrass/Level1): Entered(the test (/mob), Level1 (274,252,1) (/turf/CombatGrass/Level1))
runtime error: Cannot read null.haste
proc name: Create Order (/mob/proc/Create_Order)
source file: BattlePrep.dm,67
usr: the test (/mob)
src: the test (/mob)
call stack:
the test (/mob): Create Order(/list (/list), /list (/list), the test (/mob))
the test (/mob): Initiate Battle("level1")
Level1 (275,252,1) (/turf/CombatGrass/Level1): Entered(the test (/mob), Level1 (274,252,1) (/turf/CombatGrass/Level1))