Increment on not Gadget

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

Increment on not Gadget

Post by Cyber Spider »

Hi,

I am working on trying to create a simple game that can be showcased as "What is possible with the free edition of SpiderBasic". I am trying to increment the currency when the mouse is left-clicked, and it's not a gadget being clicked (ButtonGadget etc.). Here is the code I came up with:

Code: Select all

If Not Event() = #PB_Event_Gadget
  currency()\value+1
  SetGadgetText(currency()\handle,currency()\name + ": " + Str(currency()\value))
EndIf
However, the currency still increments when a ButtonGadget is clicked on. Any ideas?

Sincerely,

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

Re: Increment on not Gadget

Post by Paul »

Building on code from your other post, you could do something like this...

Code: Select all

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

#Button=1
Global click

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)
  ButtonGadget(#Button,250,50,100,30,"OK")
  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()
  If click=#False
    Debug "Left Click"
    ForEach currency()
      currency()\value+1
      SetGadgetText(currency()\handle,currency()\name+": "+Str(currency()\value))
    Next
    Else
    click=#False
  EndIf
EndProcedure

Procedure GadgetEvents()
  If EventGadget()=#Button
    Debug "Button Click"
    click=#True
  EndIf
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_Gadget, @GadgetEvents())
  BindEvent(#PB_Event_LeftClick,@LeftClick()) 
EndIf
Post Reply