PDA

View Full Version : get material name from it's index ??


romm
05-04-09, 07:55 PM
Hi all.

I would write a material index to an array.

I have :

[IButton,Write material index,"",

[VarSet, id,[IGetID, Material:Flat Color] ]

[VarDef, material(100)]

[Loop,100,
[VarSet,material(i),[IGetTitle, id]]
[Note, material(i),,2] // debug
[VarAdd, id, 1]
,i
]
]


which works up to a point
then fails with :

ZScript Note : Inerface item could not be found.
10258
in...
[IGetTitle,id]

clearly i am not using the correct way of obtaining the material name from it's index.

is there a more robust way of doing this ?

marcus_civis
05-04-09, 11:41 PM
I think the problem is that the numerical IDs for materials are not necessarily consecutive. This is causing your script to fail when there's no material for the ID. A solution might be to use [IExists to only return those IDs that exist but this way is simpler. Note that the Title returned from the Item Info slider has a period at the end which is trimmed off using [StrExtract:

[IButton,"Write material index","Popup info",
[VarSet,tmp,[IGet,Material:ItemInfo]]
[VarSet, id,[IGetMin,Material:ItemInfo]]
[VarSet,MaxMat,[IGetMax,Material:ItemInfo]]
[VarDef, mats(MaxMat),""]
[Note,[StrMerge,MaxMat," materials"],,1]
[Loop,MaxMat,
[ISet,Material:ItemInfo,id]
[VarSet,mats(i),[IGetTitle, Material:ItemInfo]]
//trim off period:
[VarSet,mats(i),[StrExtract,mats(i),0,[StrLength,mats(i)]-2]]
[Note, [StrMerge,id," : ",mats(i)],,.5] // debug
[VarAdd, id, 1]
,i]
[ISet,Material:ItemInfo,tmp]
]

A further note: using 'material' as a variable name caused an error for me.

HTH,

romm
05-06-09, 06:40 AM
hey thanx a stack
marcus
I'll get the hang of this some day