ID:141227
 
Code:
                if("Token") list.decklist.Add(new /obj/cards/token())
if("Monster Token") usr.decklist.Add(new /obj/cards/tokenmon())


Problem description:
So, I've been squeezing myself against this several days. I' trying to write a deck management system for a friend's game, but I don't seem myself to find the way to do it the way he wants. I offered him to do it like in DuelZ (on which cards go into a verb tab instead of a forsaken variable), but he wants it to have a nifty management window... so here I am.

I've been looking up and down, running throught Dream Maker's articles, code demostrations, the Byond Reference, and the byond guide, which currently show no sample code about list.Add (or, at least, I wasn't smart enough to find them ;w; ).

forms.dm:34:error:usr.decklist.Add:undefined proc
forms.dm:33:error:decklist :invalid expression
forms.dm:33:list :warning: statement has no effect


Line 34 is the second one shown in the code. I'm using the htmlib by dantom to produce the forms.
It's probably giving out errors because the var isn't defined as a list. And using += should be more efficient when adding single items.

Putting up code of just of the line an error points to really isn't giving alot of info.
In response to T3h P3ngu1n
T3h P3ngu1n wrote:
It's probably giving out errors because the var isn't defined as a list. And using += should be more efficient when adding single items.

Putting up code of just of the line an error points to really isn't giving alot of info.

Thanks, that's all I required to know. ^^; I couldn't find any info about, prolly because lacking searching skills.

Thanks again.
In response to Begeo
Begeo wrote:
Thanks, that's all I required to know. ^^; I couldn't find any info about, prolly because lacking searching skills.

Thanks again.

Now is a good time to get those searching skills up to date :)

First, you have two online reference guides which are reachable from the drop down menus at the top of the site:
Reference and Guide. Find them under the Developers menu.

From Guide (which I heartily recommend anyone read from front to back), there's a chapter completely dedicated to lists.
In response to CriticalBotch
CriticalBotch wrote:
Begeo wrote:
Thanks, that's all I required to know. ^^; I couldn't find any info about, prolly because lacking searching skills.

Thanks again.

Now is a good time to get those searching skills up to date :)

First, you have two online reference guides which are reachable from the drop down menus at the top of the site:
Reference and Guide. Find them under the Developers menu.

From Guide (which I heartily recommend anyone read from front to back), there's a chapter completely dedicated to lists.

I must be completely dumb then. o.o

I've readed all my way throught the guide, but both, reference and guide aren't opening a crack on my head. As well as now I can get an /obj/ type object into a list, I'm having problems accessing the obj's information in order to retrieve and show it. I must be doing it all wrong.

Form
deckmanage
reset= "Undo Changes"
submit= "Save Changes"

var

deckname = "Nameless Deck"

addmonstercard
addmonstercard_interface=SELECT
addmonstercard_values=list("Token", "Monster Token", "Gear Token", "Evolved Token", "Token Spell")

/*showdeck
showdeck_interface=SELECT*/


/*removecard
removecard_interface=SELECT
removecard_values*/


Initialize()
/*var/totalcardtext = ""

var/obj/cards
for(/obj/cards/allcards in usr.decklist)
totalcardtext += "<img src='[src.icon]'/>"*/



HtmlLayout()

return{"
Deck Name:<br>
[deckname]<br>
<br>
Add card:
[addmonstercard]<br><br>
Your deck:<br>
[usr.decklist]<br>
[submit][reset]
"}


ProcessForm()
switch(addmonstercard)
if("Token")
usr.decklist += new /obj/cards/allcards()
usr.decklist[list.len].icon = 'lulzworks.dmi'
/*if("Monster Token")
usr.decklist += new /obj/cards/tokenmon()*/

I tried accessing the object in an array manner... maybe I'm doing it wrong... Now I'm getting an "expected end of statement". X x;

-Duh, I almost forgot:
loading Duel Masters Challenge.dme
forms.dm:46:error: .: expected end of statement

Duel Masters Challenge.dmb - 3 errors, 0 warnings (double-click on an error to jump to it)


Further Explanation since last post
I found out that I couldn't show all the items in the list throught a for list proc, so I thought that just making a solely /obj/ item that can change it's gfx and text settings (Icon, name, desc) as I define could make it easier. The problem is that I don't seem to be able to access to those.
In response to Begeo
Begeo wrote:
I must be completely dumb then. o.o

I highly doubt it. I imagine, based on what it looks like you're doing, that you're used to C/C++/C# and how arrays are handled within those languages. DM is only based on C/C++; it sacrifices some power in exchange for ease of use.

I've readed all my way throught the guide, but both, reference and guide aren't opening a crack on my head. As well as now I can get an /obj/ type object into a list, I'm having problems accessing the obj's information in order to retrieve and show it. I must be doing it all wrong.

>       ProcessForm()
> switch(addmonstercard)
> if("Token")
> usr.decklist += new /obj/cards/allcards()
> usr.decklist[list.len].icon = 'lulzworks.dmi'
> /*if("Monster Token")
> usr.decklist += new /obj/cards/tokenmon()*/

I tried accessing the object in an array manner... maybe I'm doing it wrong... Now I'm getting an "expected end of statement". X x;

-Duh, I almost forgot:
loading Duel Masters Challenge.dme
forms.dm:46:error: .: expected end of statementDuel Masters Challenge.dmb - 3 errors, 0 warnings (double-click on an error to jump to it)

Further Explanation since last post
I found out that I couldn't show all the items in the list throught a for list proc, so I thought that just making a solely /obj/ item that can change it's gfx and text settings (Icon, name, desc) as I define could make it easier. The problem is that I don't seem to be able to access to those.

The problem is with how you are accessing the stored object.
listname[index] does indeed return the item at that index, but DM doesn't know what that is off-hand. It could be a datum (no icon), text, number, another list, etc. I don't believe DM allows you to access variables and/or functions directly in the way you are attempting. I recommend creating an implicit variable:
var/obj/cards/cardname/card = usr.decklist[list.len]

Note that this is actually inefficient for what you're trying to do; I merely present it for completeness of concept.

For what you are doing, however, I suggest creating the new card first, make whatever modifications you need, and THEN add it to the list:
        ProcessForm()
switch(addmonstercard)
if("Token")
var/obj/cards/allcards/card
card.icon = 'lulzworks.dmi'
usr.decklist += card

In any event, you should avoid referencing object variables from within a list. Declare implicit variables for the type of object you're working with and use those for modifications.