ID:261346
 
I am trying var1-=var2 and I get no errors, but a runtime error: type mismatch.
Air _King wrote:
I am trying var1-=var2 and I get no errors, but a runtime error: type mismatch.

Clearly something is wrong, then, with var1; a list shouldn't be having this problem. However, this error would not be possible to diagnose from the single line you showed us; we need to see more of the code to know why it's failing.

Lummox JR
In response to Lummox JR
look at the more detailed one
In response to Air _King
Air _King wrote:
look at the more detailed one

There isn't a more detailed one
In response to Super16
oopsie where did i put that? Here:(and don't talk to me like im a newb)
mob
theif2
name="theif"
icon='theif2.dmi'
Click()
items-=backpack
usr<<"You have been mugged by [src]"

In response to Air _King
Where do you define items?

Chances are, its not defined as a list.

-AbyssDragon
In response to AbyssDragon
var/list/items
In response to Air _King
Change that to:

var/list/items = list()

You're defining the var to be of type list, but not actually making a list for it to be. One thing to remember about lists is that they're actually objects, just like mob or turf, and must actually be created before they can be used. Just like var/mob/M doesn't yet represent any mob, var/list/L doesn't yet represent any list.

-AbyssDragon
In response to Air _King
Not a list, you have to initialize it as a list() also:

mob
var
list/items
New()
items = list()
In response to Nadrew
no does work
In response to Air _King
That's not exactly the complete code (nor the correct spelling of "thief") needed to give us an idea what's wrong. You'll need to show a lot more code than just snippets for people to diagnose this stuff. You've got to show where items is defined and initialized, the procs that use it, etc. Where is obj/New(), for example?

Lummox JR
In response to Lummox JR
I didn't add obj/new because items isnt an object. And that was the code (thief spelled correct) couldn't think just slashed my back in half.
In response to Air _King
Air _King wrote:
I didn't add obj/new because items isnt an object.

I'm talking about the New() proc for the obj. var/list/items has to be initialized there, or at least somewhere. New() and Del() procs are relevant to most errors, so you should usually post them along with other stuff like the statements where variables are first declared.

Lummox JR
In response to Lummox JR
what should i do to define the variables? Just tell me in one post please.
In response to Air _King
Air _King wrote:
what should i do to define the variables? Just tell me in one post please.

You need to show us more complete code before we can even begin to diagnose what's wrong. If you only ask half a question, you only get half an answer. You've so far only given little snippets, when the problem is likely related to two or three different parts of your code.
To people who've posted snippets that you should be using (or showing) to complete what you've already given, you've said incoherent things like "no does work" without showing what you did.
In other words, put more information in your posts.

Lummox JR
In response to Lummox JR
this is what i have:

var
list
items
New()
items = list()

var/backpack

mob
Thief2
icon='thief2.dmi'
name="Thief
Click()
items -= backpack
usr<<"YOu have been mugged by [src]!"
In response to Air _King
It should be a mob var and be initilaized at mob/New().
In response to Nadrew
mob
var
list
items
New()
items = list()

I have that, but when i do this in another proc:

usr<<"[src] stole [items]" it give me a "/list" output. I know it is a list, but how would i make it display the contents of the list? loop through it? let me try that.
In response to Air _King
Air _King wrote:
usr<<"[src] stole [items]" it give me a "/list" output. I know it is a list, but how would i make it display the contents of the list? loop through it? let me try that.

Yes, you'll have to loop through the list. BYOND doesn't show list contents by default.

I suggest you call a proc like this:
proc/ItemsToText(list/items,conj="and")  // this can be a global proc
var/t
if(!items.len) return ""
if(items.len==1) return "\a [items[1]]"
if(items.len==2) return "\a [items[1]] [conj] \a [items[2]]"
t=""
for(var/i=1,i<items.len,++i) t="[t]\a [items[i]], "
return "[t][conj] [items[items.len]]"

...
// now in your theft proc:
usr<<"[src] stole [ItemsToText(items)]."

Hope that helps you. I use a proc like this myself, though I also have versions where I leave off the \a. The optional second argument, conj, is so you can say things like "x, y, or z" instead of "x, y, and z". ("Then" is another good choice.) You may never need it, but it's nice to have around.

Lummox JR
In response to Lummox JR
Damn, that's practically the spitting image of my ThingyList() proc that I made a year or so ago. =P