To make a upgrade, necessarily some if's, but to economize time, can you make a thing like this:
//Example function of button and money
if buttonPressed(upgrade_click) and money >= upgrade_click_money then //If you have money to this
money = money - upgrade_click_money
upgrade_click_money += inflation
auto_clicks = auto_clicks + 1
end
init = function()
every 1 seconds do //Every second do something
clicks += 1 * auto_clicks //This makes you don't make several if's
end
end
Note: If you want the time to decrease, you can create a variable called 'autoclicker_time', or any name you prefer, and with each upgrade, it decreases, and then you can put
every autoclicker_time seconds do
this makes the delay decrease!
However, this is the fastest and easiest way, so there may indeed be errors (rare). And it usually works for various cases. I hope I helped with something.
Buttons:
LIBs(exportable pre-written codes to help):
the code:
draw = function()
if IMGUI.button("TEST1",-30,20) then
button_clicks += 1
end
//Other drawing thing's...
end
uses: Menu, UI, button of play(left, right, jump, etc), etc...
Not is possible stylize... But is fast and easy!
Can you use 'touchButtons' LIB.
Is more complex than IMGUI... But stylizable!
This code is from Touch Buttons. Link: https://microstudio.dev/i/JimB007/touchbuttons/
Code:
update = function()
// Update the touch buttons each frame
touchbuttons.update()
// Get button clicked (0 means none were clicked)
if touchbuttons.clicked==btnToggledEnabled then
btnFinal.enabled=not btnFinal.enabled
end
if touchbuttons.clicked==btnToggledVisible then
btnFinal.visible=not btnFinal.visible
end
// If a button was clicked grab its label name
if touchbuttons.clicked!=0 then
lastpressed=touchbuttons.clicked.label
end
end
note: To show the button, put on draw function touchbuttons.draw()
uses: Advanced menu, advanced UI, etc...
No lib:
This is easy to do.
link: https://microstudio.dev/i/levi_/test/
i've modified the code with comments about what's happening in the line
code:
if size_obj>50 then //Optional(It is about a click effect, a shrinking effect, and returning to size. It is necessary to place a draw, put the sprite, and set the width and height to the size for this to work.)
size_obj-=5 //Decreasing
end
if mouse.x>-25 and mouse.x<25 then click_x=true //He checks the ends of the object
else click_x=false end
if mouse.y>-25 and mouse.y<25 then click_y=true //He checks the ends of the object
else click_y=false end
if click_x==true and click_y==true then can_click=true//If the mouse is within the edges of the object, it can click.
else can_click=false end
if mouse.press and can_click==true or keyboard.SPACE and can_click==true then
number+=click_pow*multiply
size_obj=70
ptimer+=1
click=true
end
but... It's somewhat counterintuitive, but it's the same in the framework; however, you need to know exactly the position of the button in each corner, but the microstudio shows it, so there's no problem. But is stilizably, any image and any text.
uses: All, shoot, button, advanced UI, advanced menu, etc...
What i recommend to you:
For the object that will be clicked:
No lib or touchbuttons(https://microstudio.dev/i/JimB007/touchbuttons/).
Why: It is more customizable, it can be an image.
For the upgrades:
IMGUI.
Why: IMGUI(https://microstudio.dev/i/gilles/imgui/) is aimed at simple buttons, like a menu.
//Sorry my English, I don't speak English well
I hope this will useful!