ID:148673
 
mob/verb/attack(mob/M as mob in oview(usr)) //Attack verb
set hidden=1
if(M && M!=usr)
if(usr.fighting)
return
if(M.type!=/mob/player && M.ai==0)
usr<<"[M]: [M.turndown]"
return
else
if(M.fighting==0)
M.move=0
usr.move=0//Make sure they cant move
M.hadturn=0
usr.hadturn=0//Make sure they get their turn
M.Turn()
M.opponents.Add(usr)
//---^ This is the problem!//

//Just the beginning snippet//

Now it seems allright, im trying to add usr to the other mob's opponent's list which is defined as

mob/var/opponents[]=new/list()

Now here is the error I get

runtime error: Cannot execute null.Add().
proc name: attack (/mob/verb/attack)
source file: macro verbs.dm,78
usr: NeoHaxor (/mob/player)
src: NeoHaxor (/mob/player)
call stack:
NeoHaxor (/mob/player): attack(Dragonball Character (/mob/characters/AI/dragonball))

Which is basically saying it either cant read the Mob or the list variable that accompanies it, and It seems that I have tried everything. Any suggestions?

--Ken--
NeoHaxor wrote:

Now it seems allright, im trying to add usr to the other mob's opponent's list which is defined as

mob/var/opponents[]=new/list()


Do you need the [] after opponents? I thought that [] were for declaring arrays (at least in java), but not for lists.
In response to OneFishDown
OneFishDown wrote:
NeoHaxor wrote:

Now it seems allright, im trying to add usr to the other mob's opponent's list which is defined as

mob/var/opponents[]=new/list()


Do you need the [] after opponents? I thought that [] were for declaring arrays (at least in java), but not for lists.

Hey Ken try mob/list/var/opponets=new/list()

OneFishDown...He needs the /list in there but not the []
In response to DBZ Kidd
That's what I said, though it might've come out wrong. I am not sure about arrays in DM, but i know [] are used to declare them in Java, so I assumed the same for DM. This var he is declaring is a list, so the [] wouldn't be needed.
In response to DBZ Kidd
Actually, it would mob/var/list/opponents=new/list() if you didnt want the brackets. mob/list/var/opponents=new/list would just declare the opponents variable for the type of /mob/list so it wouldnt work as you wanted it to.
I tried declaring it the other way also, but still the same error.

runtime error: Cannot execute null.Add().
proc name: attack (/mob/verb/attack)
source file: macro verbs.dm,78
usr: NeoHaxor (/mob/player)
src: NeoHaxor (/mob/player)
call stack:
NeoHaxor (/mob/player): attack(Character (/mob/characters/AI))

Thanks for trying though, I just really need to fix this lol.

--Ken--
In response to NeoHaxor
Why don't you try:

var/list/Opponents = new/list

and then use that.

You don't need type-specific lists in order to add things like ATOMS. Ambiguity is ok sometimes :-)

One Fish Down:
This isn't Java it's DM
In response to ShadowWolf
But [] still works in DM, regardless. It's more compact, too, for defining a list.
NeoHaxor wrote:
Now it seems allright, im trying to add usr to the other mob's opponent's list which is defined as

mob/var/opponents[]=new/list()

And yet that's not a valid definition. Biggest problem: You can't initialize the list at compile time unless you want all mobs to share the exact same list. It has to be initialized in mob/New(), mob/Login(), or elsewhere.
mob
Login()
..()
opponents=list()
For defining it, I'd lose the brackets; they only confuse the issue. Instead just make sure it's defined as a list.
mob
var/list/opponents

Lummox JR
In response to ShadowWolf
ShadowWolf wrote:
This isn't Java it's DM

Yea I know that, but they are very similiar.
In response to OneFishDown
A list in DM is an array. I'm sure Dantom considered calling them arrays, but opted for list, as it would be a more descriptive name for those not familiar with programming jargon.

~X
In response to Lummox JR
I did this but I still get the same error. Is it possible that it isnt reading the mobile? My verb starts with mob/verb/Attack(mob/M in oview(1)), I have other errors, but they all basically state the mob as a null example null.Add() or runtime error: Cannot read null.ai
Those two are biggies, any suggestions?

--Ken--
In response to NeoHaxor
NeoHaxor wrote:
I did this but I still get the same error. Is it possible that it isnt reading the mobile? My verb starts with mob/verb/Attack(mob/M in oview(1)), I have other errors, but they all basically state the mob as a null example null.Add() or runtime error: Cannot read null.ai
Those two are biggies, any suggestions?

null.Add() means that the list is null, not the mob (although null.ai would probably be the mob). That to me suggested your initialization was part of the problem. If at any time the list is deleted, though, or set to null, you might see the same problem.

Lummox JR
Wait a minute... that's a hidden command. Does that mean you're calling it with a macro? Macros don't accept variable arguments (you can call them with fixed arguments, of course, like "look north", "look east", etc.).
Scince this was the only real bit of coding I have so far *nothing revolves around it*, I figure I will comment everything out until later and make it differently, but with the same idea.

Thanks for your help everyone, I did learn some things in this process.

--Ken--
Try defining opponents[] as:

<code>mob/var/opponents[0]</code>

Works for me. :-)