• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

expecting class member declaration

Callumk0104

New member
Joined
Feb 6, 2018
Messages
20
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
 
Difficult to judge what is wrong without the error message and actual code to try.
 
Also the last parameter of the New method is an Image but you pass a string.
 
Ok, tried to replicate it with your code pieces. Your New Method assigns values that are not parameters of the Methods parameters.
 
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
 
Place an END in line 95 and it works.

Like I said, with incomplete informations, it is hard to help.
 
I have added the End to the line, it then gives me an error of the case being an unexpected token 'case'.
 
Last edited:
Back
Top Bottom