Syntax error - expecting class member declaration.
Monkey Forums/Monkey Beginners/Syntax error - expecting class member declaration.
| ||
hi all, problem with this code: Strict Import Utilities Import mojo class TPalette Field color_table:Int[][] Method New(url:String) 'Local file:TStream Local byte_array:Byte[] Local j:Int 'file=OpenStream(url, True, False) byte_array = LoadByteArray(url) color_table = New Int[(Len(byte_array) / 3)][3] For Local i:Int = 0 To Len(byte_array) - 1 j = i Mod 3 color_table[(i / 3)][j] = byte_array[i] Next End Method Method initCopy:void(Ipal:TPalette , choice:Int[]) Local tr:Int Local tg:Int Local tb:Int color_table = New Int[Len(choice)][3] For Local i:Int = 0 To Len(choice) - 1 Ipal.giveColor(choice[i] , tr , tg , tb) color_table[i][0] = tr color_table[i][1] = tg color_table[i][2] = tb Next End Method Method useColor:void(index:Int) SetColor (color_table[index][0],color_table[index][1],color_table[index][2]) End Method Method giveColor:Int[](index:Int) Local rgb:Int[3] ' 2014 rgb[0] = color_table[index][0] ' 2014 rgb[1] = color_table[index][1] ' 2014 rgb[2] = color_table[index][2] ' 2014 Return rgb ' 2014 End Method Method Length:Int() Return (Len(color_table) / 3) End Method End class Class MyApp Extends App Field paletteA:TPalette = New TPalette("Default.act") Field paletteB:TPalette Field pal_select:Int[] = [22 , 53 , 72 , 115 , 187 , 29] paletteB.initCopy(paletteA , pal_select) End class I receive the error message "expecting class member decalration" on the line "paletteB.initCopy(paletteA , pal_select)" I don't understand why ? the method call seems to be ok ? if someone has an idea, this could be great :-) Pit |
| ||
paletteB.initCopy is a method call? It should be in the body of a function or method. The class body only accepts the class description (fields, const, globals, method and function declarations). Then, inside the function or method, you can have actual code including function calls. |
| ||
First wrap you code in [ code ] or [ codebox ] forum statements so it is readable. http://www.monkey-x.com/Community/posts.php?topic=8634#forum-codes-content Second in your MyApp class, you are trying to call a procedure in the field declaration section. Class MyApp Extends App Field paletteA:TPalette = New TPalette("Default.act") Field paletteB:TPalette Field pal_select:Int[] = [22 , 53 , 72 , 115 , 187 , 29] paletteB.initCopy(paletteA , pal_select) End class Should be something like: Class MyApp Extends App Field paletteA:TPalette = New TPalette("Default.act") Field paletteB:TPalette Field pal_select:Int[] = [22 , 53 , 72 , 115 , 187 , 29] Method OnCreate:Int() paletteB.initCopy(paletteA , pal_select) Return 0 End End class |
| ||
the revills, thank you !!! for the tip for displaying code (I searched a liitle bit but didn't find it :-) ! for your answer about my error ! I'm completely stupid. It's my first conversion from blitzmax..... I hope I will more use in the future to play with class.... :-) |
| ||
This kind of error is nearly always the result of unmatched entry or exit to code blocks - could be any of If..End, For..Next, Class..End etc. or similar structural errors, somewhere before the line where compilation stops/ |