expecting class member declaration

Callumk0104

New Member
Joined
Feb 6, 2018
When running my code I keep getting an issue with it expecting class member declaration, so far my class consists of the code as shown.

Code:
Class Item
    Field name:String
    Field amount:String
    Field item1:String
    Field item2:String
    Field img:Image
   
    Method New(itemName:String, itemAmount:String, craft1:String, item2:String, img:Image)
    name = itemName
    amount = itemAmount
    item1 = craft1
    item2 = craft2
    img = image
Also if needed, here is the code which it is creating a new instance of this class in.

Code:
        Case "NEWGAME"
               
                Local NewFile:FileStream
                Local fileString:String
                Local itemLine:String[]
                itemCollection = New List<Item>
           
               
                NewFile = FileStream.Open("monkey://data/Saves/saveTemplate.txt","r")
                fileString = NewFile.ReadString()
                NewFile.Close
                   
                itemLine = fileString.Split("~n")
                For Local item:=Eachin itemLine
                    itemCollection.AddLast(New Item(itemLine[item], itemLine[item+1], itemLine[item+2] ,itemLine[item+3] ,itemLine[item+4]))
                    item += 5
                End
 

MikeHart

Administrator
Staff member
Joined
Jun 19, 2017
Location
Germany
Difficult to judge what is wrong without the error message and actual code to try.
 

MikeHart

Administrator
Staff member
Joined
Jun 19, 2017
Location
Germany
Ok, tried to replicate it with your code pieces. Your New Method assigns values that are not parameters of the Methods parameters.
 

Callumk0104

New Member
Joined
Feb 6, 2018
Here's my full program, I'm unsure what you mean by the parameters of the Methods parameters, I have looked over again and changed the naming of the parameters where they were incorrect and get the same issue. Thanks

Code:
Import mojo
Import brl
Import brl.FileSystem

Global Discovery:Game
Global QuitApp:Int
Global NewFile:FileStream
Global itemCollection:List<Item>

Function Main()
    Discovery = New Game
End

Class Game Extends App

    Field Menu:Image
    Field NewGameButton:Image
    Field LoadGameButton:Image
    Field OptionButton:Image
    Field QuitButton:Image
    Field CollisionCheck:Bool
   
   
    Field itemLine:String[]
   
    Field CraftingScreen:Image
   
   

   
   
    Global Gamestate:String = "MENU"
    Global Savename:String

    Method OnCreate()
   
        SetUpdateRate 60
       
        Menu = LoadImage("menu-background.png")
        NewGameButton = LoadImage("newGameButton2.png")
        LoadGameButton = LoadImage("loadGameButton2.png")
        OptionButton = LoadImage("optionsButton2.png")
        QuitButton = LoadImage("quitButton2.png")
       
        CraftingScreen = LoadImage("craft.background.png")
       
    End
   
    Method OnUpdate()
        Select Gamestate
       
            Case "MENU"
                If KeyHit(KEY_LMB) Then
                    CollisionCheck = boundingBox(780, 380, 455, 91, MouseX(), MouseY())
                    If CollisionCheck = True
                        Gamestate = "NEWGAME"
                    Elseif KeyHit(KEY_LMB) Then
                        CollisionCheck = boundingBox(780, 521, 455, 91, MouseX(), MouseY())
                        If CollisionCheck = True
                            Gamestate = "LOADGAME"
                        Elseif KeyHit(KEY_LMB) Then
                            CollisionCheck = boundingBox(780, 662, 455, 91, MouseX(), MouseY())
                            If CollisionCheck = True
                                Gamestate = "OPTIONS"
                            Elseif KeyHit(KEY_LMB) Then
                                CollisionCheck = boundingBox(780, 803, 455, 91, MouseX(), MouseY())
                                If CollisionCheck = True
                                    EndApp()
                                End
                            End
                        End
                    End
                End
           
            Case "NEWGAME"
               
                Local NewFile:FileStream
                Local fileString:String
                Local itemLine:String[]
                itemCollection = New List<Item>
           
               
                NewFile = FileStream.Open("monkey://data/Saves/saveTemplate.txt","r")
                fileString = NewFile.ReadString()
                NewFile.Close
                   
                itemLine = fileString.Split("~n")
                For Local item:=Eachin itemLine
                    itemCollection.AddLast(New Item(itemLine[item], itemLine[item+1], itemLine[item+2] ,itemLine[item+3] ,itemLine[item+4]))
                    item += 5
                End
                   
                Gamestate = "CRAFTING"   
                   
                   
            Case "LOADGAME"
           
            Case "CRAFTING"
           
           
           
            Case "PAUSE"
           
            Case "OPTIONS"
           
            Case "INVENTORY"
           
            Case "HOWTO"
        End
    End
   
    Method OnRender()
        Select Gamestate
           
            Case "MENU"
                DrawImage(Menu, 0, 0)
                DrawImage(NewGameButton, 780, 380)
                DrawImage(LoadGameButton, 780, 521)
                DrawImage(OptionButton, 780, 662)
                DrawImage(QuitButton, 780, 803)
               
            Case "NEWGAME"   
                Cls(255, 0, 0)
               
               

               
            Case "CRAFTING"
                DrawImage(CraftingScreen, 0, 0)
               
           
            Case "PAUSE"
           
            Case "OPTIONS"
           
            Case "INVENTORY"
           
            Case "HOWTO"
        End           
    End

End

Class Item
    Field name:String
    Field amount:String
    Field item1:String
    Field item2:String
    Field img:Image
   
    Method New(itemName:String, itemAmount:String, craft1:String, craft2:String, image:String)
    name = itemName
    amount = itemAmount
    item1 = craft1
    item2 = craft2
    img = image
   
       
End

Function boundingBox:Bool (x1:Int, y1:Int, w1:Int, h1:Int, mouseX, mouseY)
    Local Xmax:Int
    Local Ymax:Int
    Xmax = x1 + w1
    Ymax = y1 + h1
    If mouseX > x1 And mouseX < Xmax And mouseY > y1 And mouseY < Ymax
        Return True
    Else
        Return False
    End   
End
 

Callumk0104

New Member
Joined
Feb 6, 2018
I have added the End to the line, it then gives me an error of the case being an unexpected token 'case'.
 
Last edited:
Top Bottom