Class: avatar
API
The class only has one method parser(file), where file is the name of the attribute file without the .avt extension.Misc.
The power of Unicon (the programming language used to develop the avarcron) is shone in this class and throughout other classes in the area of text processing. Notice the bolded texts down below, where an expression sentence[i+1:*sentence+1] thrives. In Unicron, string can be manupilated in many ways, and this is one of them. One can extract a part of string (i.e. substring) with two indices. Thus, considering a string word:="school", a substring "choo"can be extracted by saying word[2:5].Source Code
class avatar( # Avatar information name, # Name sex, # Gender hdchoice, # Head Shape (1 for square;2 for egghead) face, # Name of the face picture file xsize,ysize,zsize, # X,Y,Z scalor factors height, # Y-axis Scalar factor (i.e. = ysize) color, # Primary color (Skin color) scolor, # Shirt color pcolor, # Pants color shcolor # Shoes color ) # # parser(File) # Purpose: Takes a file and parse each line and set them to their # appropriate variables # method parser(file) local line, count count:=0 line:= open(file||".avt") | stop("Can't open ", file||".avt") while sentence:=read(line) do { sentence:=trim(sentence,'\t') sentence:=trim(sentence,' ') if sentence[1]~=="#" then { i:=1 while i < *sentence do { if sentence[i] == "=" then { break } i:=i+1 } if count == 0 then { name:=sentence[i+1:*sentence+1] } else if count == 1 then { sex:=sentence[i+1:*sentence+1] } else if count == 2 then { height:=sentence[i+1:*sentence+1] } else if count == 3 then { xsize:=sentence[i+1:*sentence+1] } else if count == 4 then { ysize:=sentence[i+1:*sentence+1] } else if count == 5 then { zsize:=sentence[i+1:*sentence+1] } else if count == 6 then { color:=sentence[i+1:*sentence+1] } else if count == 7 then { scolor:=sentence[i+1:*sentence+1] } else if count == 8 then { pcolor:=sentence[i+1:*sentence+1] } else if count == 9 then { shcolor:=sentence[i+1:*sentence+1] } else if count == 10 then { hdchoice:=sentence[i+1:*sentence+1] } else if count == 11 then { face:=sentence[i+1:*sentence+1] } count:=count+1 } } end initially() i:=0 name:="guest" xsize:=0 ysize:=0 zsize:=0 height:=170 origx := 0 origy := 0 origz := 0 sex := "m" face := "smily.gif" hdchoice := 1 end