[17:29:56] [COMPILER] Line 39: Module not found: stars_currency.

Just starting out? Need help? Post your questions and find answers here.
Cyber Spider
Posts: 8
Joined: Fri Jun 02, 2023 10:53 am

[17:29:56] [COMPILER] Line 39: Module not found: stars_currency.

Post by Cyber Spider »

Hi,

I am getting the following error when i try to compile my code:
[17:29:56] [COMPILER] Line 39: Module not found: stars_currency.
Here is the code I am using:

main.sb

Code: Select all

; include all the required modules
XIncludeFile "input.sb"
XIncludeFile "currency.sb"
XIncludeFile "app.sb"

; module use declaration
UseModule Input
UseModule Currency
UseModule App

; initalize the input environment
Input::init()

App::createWindow()
Global stars_currency = Currency::create("Stars", 50, 50)
app.sb

Code: Select all

DeclareModule App
  ; procedures
  Declare createWindow()
  Declare eventHandler()
  Declare update()
  Declare render()
EndDeclareModule

Module App
  ; window handle
  Global windowHandle

  ; procedure to create the window
  Procedure createWindow()
    ; examine the desktop for it's width and height
    ExamineDesktops()
    
    ; open a window with it's width and height half of the desktop width and height
    windowHandle = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0) / 2, DesktopHeight(0) / 2, "Idle Game")
  EndProcedure

  Procedure eventHandler()
    Select Event()
    EndSelect
    
    ; update the game states
    update()
    
    ; render the game states
    render()
  EndProcedure

  Procedure update()
    ; poll for input
    Input::poll()
    
    ; if the mouse button has been pressed
    If Input::hasClicked()
      stars_currency::increment()
    EndIf
  EndProcedure
  
  Procedure render()
  EndProcedure
EndModule

; bind the event queue to it's handler
BindEvent(0, eventHandler)
currency.sb

Code: Select all

DeclareModule Currency
  ; procedures
  Declare create(name.s, x.c, y.c)
  Declare increment()
EndDeclareModule

Module Currency
  ; canvas to draw on
  Global gadget
  
  Global name.s = ""
  
  Global value.l = 0
  
  ; create the currency
  Procedure create(name.s, x.c, y.c)
    gadget = TextGadget(#PB_Any, x, y, 100, 100, "" + name + ": " + value)
    ProcedureReturn gadget
  EndProcedure
  
  Procedure increment()
    value = value + 1
    Debug "Value: " + value
  EndProcedure
EndModule
input.sb

Code: Select all

DeclareModule Input
  ; procedures
  Declare init()
  Declare poll()
  Declare hasClicked()
EndDeclareModule

Module Input
  ; initalized?
  Global.b initalized = 0
  
  ; has the user interacted
  Global.b input = 0
  
  ; create the currency
  Procedure init()
    InitMouse()
  EndProcedure
  
  Procedure poll()
      ; scan the mouse
      ExamineMouse()
    
    If MouseButton(#PB_MouseButton_Left)
      input = 1
    Else
      input = 0
    EndIf
  EndProcedure
  
  Procedure hasClicked()
    ProcedureReturn input
  EndProcedure
EndModule
Could someone please tell me what I am doing wrong?

Sincerely,

Cyber Spider
Last edited by Cyber Spider on Mon Jun 05, 2023 1:29 pm, edited 1 time in total.
User avatar
Paul
Posts: 195
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

Re: [17:29:56] [COMPILER] Line 39: Module not found: stars_currency.

Post by Paul »

The compiler is telling you what you are doing wrong here ;)
Module not found: stars_currency.

If you look at app.sb you have the line...
stars_currency::increment()

In currency.sb your module is called Currency so you must call it
currency::increment()

Also, if you use UseModule then you would simply use create instead of Currency::create

Things would also be less convoluted if you simply used Procedures instead of wrapping everything as Modules for no good reason.
Cyber Spider
Posts: 8
Joined: Fri Jun 02, 2023 10:53 am

Re: [17:29:56] [COMPILER] Line 39: Module not found: stars_currency.

Post by Cyber Spider »

Paul wrote: Sun Jun 04, 2023 10:50 pm The compiler is telling you what you are doing wrong here ;)
Module not found: stars_currency.

If you look at app.sb you have the line...
stars_currency::increment()

In currency.sb your module is called Currency so you must call it
currency::increment()

Also, if you use UseModule then you would simply use create instead of Currency::create

Things would also be less convoluted if you simply used Procedures instead of wrapping everything as Modules for no good reason.
According to the official help text
Modules are an easy way to isolate code part from the main code, allowing code reuse and sharing without risk of name conflict. In some other programming languages, modules are known as 'namespaces'.
I tried changing the line to

Code: Select all

Currency::increment()
but, it still doesn't work. The other issue is how do I manage the different
currency's
for example using procedures to update each currency's value?

Sincerely,

Cyber Spider
User avatar
Paul
Posts: 195
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

Re: [17:29:56] [COMPILER] Line 39: Module not found: stars_currency.

Post by Paul »

Can't point out the exact issue for you because your code is incomplete.

You posted the exact same code for currency.sb and input.sb
Cyber Spider
Posts: 8
Joined: Fri Jun 02, 2023 10:53 am

Re: [17:29:56] [COMPILER] Line 39: Module not found: stars_currency.

Post by Cyber Spider »

Paul wrote: Mon Jun 05, 2023 4:30 am Can't point out the exact issue for you because your code is incomplete.

You posted the exact same code for currency.sb and input.sb
Oh sorry here is input.sb

Code: Select all

DeclareModule Input
  ; procedures
  Declare init()
  Declare poll()
  Declare hasClicked()
EndDeclareModule

Module Input
  ; initalized?
  Global.b initalized = 0
  
  ; has the user interacted
  Global.b input = 0
  
  ; create the currency
  Procedure init()
    InitMouse()
  EndProcedure
  
  Procedure poll()
      ; scan the mouse
      ExamineMouse()
    
    If MouseButton(#PB_MouseButton_Left)
      input = 1
    Else
      input = 0
    EndIf
  EndProcedure
  
  Procedure hasClicked()
    ProcedureReturn input
  EndProcedure
EndModule
I also updated the original post.

Sincerely,

Cyber Spider
User avatar
Paul
Posts: 195
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

Re: [17:29:56] [COMPILER] Line 39: Module not found: stars_currency.

Post by Paul »

Hi Cyber Spider,
You are getting more errors because you cannot call a module from another module without first setting up a common module.

Anyway, here is a quick snippet that may give you some ideas on how to manage your multiple gadgets (if I understand correctly)...

Code: Select all

Structure curdata
  handle.i
  name.s
  value.i
EndStructure
Global NewList currency.curdata()

Procedure.i Window_Main()
  ExamineDesktops()
  windowHandle=OpenWindow(#PB_Any,0,0, DesktopWidth(0)/2, DesktopHeight(0)/2, "Idle Game",#PB_Window_SizeGadget|#PB_Window_SystemMenu)
  ProcedureReturn windowHandle
EndProcedure

Procedure Currency_Create(name.s,x,y,value)
  AddElement(currency())
  With currency()
    \handle=TextGadget(#PB_Any,x,y,100,100,name+": "+value)
    \name=name
    \value=value
  EndWith
EndProcedure


Procedure LeftClick()
  ForEach currency()
    currency()\value+1
    SetGadgetText(currency()\handle,currency()\name+": "+Str(currency()\value))
  Next
EndProcedure


If Window_Main()
  Currency_Create("Stars",50,50,0) 
  Currency_Create("Test1",50,100,50) 
  Currency_Create("Test2",50,150,33) 
  BindEvent(#PB_Event_LeftClick,@LeftClick()) 
EndIf
Post Reply