ID:156905
 
Heya.. Again, i was really hoping to try and avoid creating a new topic for awhile but i guess that didn't really go so well.

So anyways in my preview problems thread i had the problem of garbage collection yatta yatta and for the most part (i think its solved) anyways thats not the problem, the problem is that Kaioken mentioned vars that are only used during character creation (that i currently have set to tmp so there not saved) and i know this is a ineffective method i think.

So im gonna give a quick snip of codes in my creation thing and am hoping for some way to deny the vars being in the "original mob" without having to be declared tmp.

//first up a global variable that simply defines each family type so that it can be written to the boxes on winset.
var
listFamily = list("Vongola", "Cavallone", "Giglio_Nero", "Gesso")
listFamilyPic = list('Avatar_Vongola.png', 'Avatar_Cavallone.png', 'Avatar_Giglio.png', 'Avatar_Gesso.png')
listFamilyBio = list('Avatar_Vongola.png', 'Avatar_Cavallone.png', 'Avatar_Giglio.png', 'Avatar_Gesso.png')

//mob/var/tmp/CF=1//in note state due to experimenting
//second up the code that selects family etc.
FamilyRight()

usr.CF++
if(usr.CF>4) usr.CF=1
winset(src,null,"familypic.image=[listFamilyPic[usr.CF]]; familyname.text=[listFamily[usr.CF]]; familybio.image=[listFamilyBio[usr.CF]]")
usr.Family = listFamily[usr.CF]

//third up the code that is repeated in 3 different formats to output a bunch of objects to grids.
//mob/var/tmp/Skinoptions //currently in note state due to experimenting.
mob/proc/BuildSkinGrid() //as seen in the code it pulls all the objects under the type of skinselection.
var/mob/creation/p = new() //links this to the mob creation so that it will display the skins
var/list/SkinoptionsA = list()
for(var/V in typesof(/obj/SkinSelection)-/obj/SkinSelection)
SkinoptionsA += new V
p.Skinoptions = SkinoptionsA //makes it so that list what is created is set to the mob creation so it will output

var/Skins = 0
for(var/obj/SkinSelection/O in p.Skinoptions)
src << output(O, "basegrid:[++Skins]")

//and finally the junky experiment thing which is currently failing.
mob/creation
var/Skinoptions
Family = "Choc"
CF=1


so yeah what i was experimenting with was a new mob of some form that would take the vars that define the position of the family slider,and the var that holds the skins.

Now what this experiment did was.

1. For the family slider i could only slide across one of the family's and it would just freeze in place.

2. for the outputter of the skins it outputs them perfectly but is now getting garbage collected(unlike previously where it worked fine) but im trying to eliminate those unneeded vars etc from the mob so there not stuck with it forever.



So yeah, any thoughts on this are appreciate, Preferred if being linked to decent guides/demos that cover this in detail would be nice. just a general point in the right direction and any "code improvement tips" are welcomed .

Thanks Again
~Midget
Any reason why the skin options couldn't be global vars like the family ones?

You could also create a modal input which isn't covered much in BYOND. Here would be an example:

SkinPrompt
var
selected = 0
list/options = NULL

New(client)
if(client)
ShowModal(client)

proc
ShowModal(client, timeout=600)
options = list()
for(var/skin_type in typesof(/obj/SkinSelection)-/obj/SkinSelection)
options += new skin_type(src) // the skins probably dont need to interact with the mob directly, instead they can get what they need from this input object

Display(client)

// you will need a way to signal this prompt that a selection has been accepted or canceled
// this can be accomplished a bunch of different ways, the easiest probably being adding a /obj/SkinSelectionButton to the mob's contents with a verb that could be triggered by a Button widget in the skin.
spawn(timeout) // You only have 60 seconds!
if(src && !selected)
selected = -2 // -2 could be timeout value, -1 a cancel value, and positive integers could be an index to a list or something smart

while(!selected)
sleep(5)

return selected // or some object that makes more sense

Display(client)
// use this to display and update the input interface


// You can then prompt the user for skin selection:

mob
Login()
name = NamePrompt()
age = AgePrompt()
do
skin = SkinPrompt(client)
while(skin <= 0) // keep prompting until an acceptable value is passed



That's one way to eliminate one-time use vars, and I use this method for hub://Crashed.crashColour if you want to see it in action. Hope it helps.
In response to Crashed
Hmm not quite sure how this fully works, so ill leave it for now till i can understand it properly.

In any case i decided to try and fiddle with making it a Global Variable and also making a world proc thats launched on world start, now im not quite sure if this is actually an effective method so some quick feedback would be nice.

world/New()  
..()
PreVar() //launches the test var im using to try world proccing.

var/Skinoptions //the world var that will hold the bases before being outputted.
proc/PreVar() //will be used to create all vars if this prooves to be an effective way of doing this.
var/list/SkinoptionsA = list() //Defines a new list
for(var/V in typesof(/obj/SkinSelection)-/obj/SkinSelection) //grabs all the objects out of this object tree
SkinoptionsA += new V
Skinoptions = SkinoptionsA //sets the global var to that of that list defined above.


client/proc/BuildSkinGrid()
var/Skins = 0 //holds the position of the skins
for(var/obj/SkinSelection/O in Skinoptions) //grabs all the skins from the variable made at world start and then gets ready to pass them out to the grid.
src << output(O, "basegrid:[++Skins]")