Coding Help for my game (hard to explain)

So basically, I have a game where miners mine a rock, and it gives a certain seed every 2.5 seconds (seed=ore). For my game I’m trying to keep the memory usage low, so I made it automatically give into your inventory. Now players can AFK the game, and I need help making code so that there is a button you can press for every mining area, that collects everything. I have 15 seeds (ores), and 6 mining areas. How do I make it so that there are delayed item grant, on button press. I don’t know how to do this without a bunch of code blocks. Is there a faster way to do this besides adding a bunch of properties and code.

1 Like

You can do this with 2 counters, and a property for each mine, and then one or two blocks depending on how many mines you have, alongside one more property.
I’ll tell you how exactly in a moment.

1 Like

by counters you mean a replacement for using blocks for number coding?

One counter would update property of the amount of times a mine has been mined, instead of having a block update it every frame.
There is a way to do this without any blocks or properties. It’s actually probably the only way to do it without having a block for each mine. You’d essentially use a trigger loop that connects to the item granter for the seed, and loops equal to the number on the counter for times mined.
Does that make any sense?

1 Like

well on mining there’s a random chance of what mineral you got, and it transmits on the channel which ore it mined

1 Like

it’s hard to do it with counters because of the luck system

1 Like

I don’t know of another way without block code to make a randomizer, so you’ll need something like this:

Mine1 button pressed start this wire loop:
1 second delay wire node —>1 second delay wire node —> 0.5 second delay trigger with the following block code:

on channel Mine1:
random number 1-15
if number = 1: give triggering player {Ore1}
if number = 2: give triggering player {Ore2}
if number = 3: give triggering player {Ore3}
#continue this until you get to 15

When the button is pressed, it either activates or deactivates the trigger in the loop, but always sends a signal to the first wire node when pressed.

Repeat this setup for every mine area you have.

OK. Does each mine contribute to a global pool of resources, or do they all have their own storage that you have to go to that particular mine to collect? Do they all have different chances of granting different seeds? Do some not have a chance of granting certain seeds at all?

1 Like

no I think he means using the counter device…
Its more groups of data not code for GKC

No they do not a different chance. Yes each mine may have to contribute their own resources. And no anything can grant any seed if it is done rightly. They all in theory have the same drop chance

1 Like

this is what I have, I just need it
to save somewhere without extensive coding (if there’s no other way idk)


3 Likes

And I’m guessing you have one of these blocks for each mine?
What you could do is, instead of storing the randomized values, you could store how many times it’s been mined and run this block for each time it’s been mined whenever the mine is collected from.
Here’s how it would look:

The wires are as such:
button pressed → relay wire pulse
button pressed → activate trigger
relay wire pulse → trigger
trigger → relay wire pulse

Your block can go as-is into the trigger.
The counter has a target value of 0, and upon reaching that target value it deactivates the trigger. The counter should increment when your mine mines, and should decrement when the trigger triggers. You’ll have one of these for each mine.
The repeater should have a 0.1 second delay.
The button is the input the player presses to collect the ores.
The whole thing shouldn’t take up too much memory, and it won’t use any properties.

The only problems with this mechanism are that it doesn’t store the ores you get before you collect them, so you can’t access them to show how much a mine has gotten so far, and that if you have a lot stored, it can take a really long time to collect all of it.
Hope this helps!

2 Likes

it does help, and I have a good idea for this. even though I don’t like using counters (code block counting is better for me) I think I could add some code to this, really simple. making the counter update a property, then using code to reset and give ores. maybe I could stack code, but the main problem is the memory usage, because then I need around 50 of these mechanisms for every island mining. any ideas for simplying it?

1 Like

The way I have it set up is the way you would solve the problem without using blocks for each item. You can’t have an item granter grant a specific amount of items at once without a block in that item granter.

If you wanted a property instead of a counter, you could decrement the property with the block in the trigger, and increment it however you want with blocks. You would also need an additional check at the end of the trigger block.

if property = 0:
deaxtivate trigger

Also, you can move the delay from the wire repeater to the trigger, as I believe the trigger delay can be smaller than 0.1.

Anyways, a trigger loop is really the only way you can grant a certain amount of items without a block in the item granter.

1 Like

Something you could do to save memory is instead of using a different if-then block for each ore, you could just extend a single it-then block using else if blocks. You do this by clicking on the blue gear and dragging the else if block into the window.

2 Likes

Is joltik your favorite Pokemon I love Joltik too

But yeah I agree with this

2 Likes

This topic was automatically closed 3 hours after the last reply. New replies are no longer allowed.