ID:139973
 
Problem description:
Since I'm trying to make this user list, a la dungeon master, I was wondering, because I keep getting this one error called type mismatch when using += to add something to a list, what exactly does it mean?
You are not initializing the list. You need to do L = list() before adding elements to it. For example:

mob
var/list/whatever = list()
In response to Garthor
Garthor wrote:
You are not initializing the list. You need to do L = list() before adding elements to it. For example:

mob
> var/list/whatever = list()


I've got to go, that didn't work. Here's my code, please tell me what's wrong when you get a chance.

[code]
mob



Stat()
stat("Gold: ", client.gold)
stat("Oil: ", client.oil)
stat("Coal: ", client.coal)
stat("Iron: ", client.iron)




Login()
loc=locate(1,1,1)
if(key=="CodeWeasel22")
client.gold=50000000
client.oil=50000000
client.coal=50000000
client.iron=50000000
var/newNation=input("What is your country?") as text
nationsIndex.Add(newNation)
var/newKing=new /mob/king(loc=locate(1,1,1))
client.king=newKing
client.unitsList=client.unitsList&&newKing
if(client.canSpawn=="true"&&key!="CodeWeasel22")
var/newNation=input("What is your nation?") as text
nationsIndex.Add(newNation)
world << "A new country has been formed, [newNation] ruled by King [key]"
var/newX=input("X?") as num
var/newY=input("Y?") as num
var/newKing=new /mob/king(loc=locate(newX,newY,1))
client.king=newKing
client.unitsList+=newKing
client.canSpawn="false"
client.gold=50
client.oil=200
client.iron=200
client.coal=400


verb
hireHuman()
if(client.gold<10)
client << "Not enough gold; you have [client.gold]"
if(client.gold>=10)
client.gold-=10
var/newHuman=new /mob/human(loc=locate(1,1,1))
newHuman:name=input("What name") as text
client.unitsList+=newHuman

zoomOut()
if(client.view<12)
client.view()++
if(client.view==12)
client << "Zoomed out to max!"

zoomIn()
if(client.view==5)
client << "Zoomed in to Max!"
if(client.view>5)
client.view()--

research()
var/toLearn=input("What do you wish to learn?") in client.researchOptions

callMeeting()
name="Call a meeting"
desc="Call a meeting of nations"
world << "King [client] has called a meeting of nations at the world center!"

deposit()













worker
icon='miner.dmi'

human
icon='miner.dmi'

king
icon='king.dmi'

var
health
maxHealth
bullets
fuel
maxFuel
isAT
selfNation

atom
tank




apc






var/global/nationsIndex[100]


turf
grass
icon = 'grass.dmi'

snow
icon = 'snow.dmi'

ice
icon = 'Ice.dmi'






obj
goldOre
icon = 'goldOre.dmi'




world




New()
..()

client
var


iron
gold
coal
oil
nation
enemies
king
researchOptions=list("Military","Civil","Industrial")
militaryResearchOptions
worldBanked
canSpawn="true"

list
unitsList

DblClick(toInteract)
world << "DblClick detected!, [unitsList], [toInteract]"
if(istype(unitsList,/mob/human)&&istype(toInteract,/obj/ goldOre))
usr.client << "Copy, moving to mine."
walk_towards(unitsList,toInteract,20)
for(unitsList in range(1))
gold+=10000000


[/code]
In response to CodeWeasel22
client.unitsList=client.unitsList&&newKing


This is setting unitsList to newKing, which isn't a list, and hence the error. Presumably, you want the + operator, not the && operator.
In response to Garthor
Okay, I removed that and still with these lines it isn't working;

[code]
DblClick(toInteract)
world << "DblClick detected!, Usr: [usr] [unitsList], [toInteract]"
unitsList+=toInteract
walk_towards(unitsList,toInteract,0)
[/code]
In response to CodeWeasel22
There are other places where you are treating unitsList as not a list, like at the end of the code snippet you posted previously.

Also: It's <DM> and </DM>, not [code][/code].
In response to Garthor
Then tell me what to do, I'm on a cruise and don't have much time.
In response to CodeWeasel22
Is somebody pushing you to finish your game?
You should have all the time it takes to learn, or, if you do not, you hire somebody.
In response to Schnitzelnagler
I am not being rushed, however I came to those who were more experienced for help, and second of all I haven't the money to hire. So can you please just tell me what's wrong?
In response to CodeWeasel22
The variable contains an instance of a mob. It should contain a list. To solve this, stop putting a mob into it.

Note that null + mob = mob.
In response to Garthor
Well I may have figured it out, thanks for at least trying to help. I tried to do that, but now when I tell it to output the list all it says is /list.
In response to CodeWeasel22
That's what's supposed to happen.

To put it in layman's terms, you're outputting the list. So that's what you get in the output, an acknowledgment of a list (since lists don't have a name or something else to represent themselves by). At any case, also note since you're outputting one untouched value, you're naturally being displayed a single value.

A list is like a container. If you want to see what's inside the list, then you need to look inside it, or in other words go through the things inside, rather than just look at the list. So if you want to output the contents of a list, you need to loop through every item in it and output that.
In response to CodeWeasel22
CodeWeasel22 wrote:
Well I may have figured it out, thanks for at least trying to help. I tried to do that, but now when I tell it to output the list all it says is /list.

There are few things that piss me off more than when somebody fails to follow my advice, finally manage to, on their own, stumble onto the exact same answer I've been giving them, and then thank me for "trying" to help, as if it was my own fault they can't read.
In response to Garthor
Quick question, would "var/list/whateverlist=new" work the same as "var/list/whateverlist=list()"?
I do this in my game when making a list and it seems to work fine but if it's going to cause problems in some way then I want to clear it up now while it's on topic.
In response to Bravo1
Yes.