How to Use Functions in Blocks (Difficulty: 4/10) Need to know about functions

Functions and blocks are currently not integrateable. This guide will solve that.
You need:
1x function
1x counter
1x property
1x trigger
maybe extra triggers if you need more blocks

First, make the function. I will use the remainder function in this guide. Next, place a counter and make it change a property. Name the property something like NumFunctionsFinished. Place the trigger. Make the property broadcast on a channel to start the trigger’s block. After this, put these blocks in the trigger:

Add as many else ifs as you need functions. After this, you should probably make sure that the function’s output broadcasts on a channel when changed. I’ll use Remainder Obtained as the channel. After this, set this channel to increment the counter.

Optional:

To cleanly run your game, you should make it so that when the block is finished, it broadcasts on a channel that deactivates a trigger that gives access to the counter. You have to change all channels leading into the counter to lead in to the trigger and then the trigger broadcasts to the counter.

Difficulty
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
0 voters

Please let me know there are any bugs in my system! I might not be able to respond immediately because I have 20 post limit for my first day.

6 Likes

Nice guide!

4 Likes

Nice topic! Although, I’d like to know how you make functions because I don’t really undersand the remainder function.

Nice Guide @getrithekd!

Wait, I’m confused. How does this integrate a function into block code?

I am also confused. What is this?

Integrate functions? I don’t think you can calculate definite integrals in gimkit.

2 Likes

How does this work? I don’t really get it.

If ClicClac doesn’t get it, barely anyone will.

4 Likes

No not integrals, but merging functions with blocks. This works because the property tracks how many time the trigger has called a function. Based on what that property is, it will choose which code to run.

Finally! I’m off my first-day 20 comment limit!

1 Like

Not integrals

If you are choosing based on how much a property is, couldn’t you just do this:

Broadcast message on channel:
J0IN
1. Example
2. Convert numbers to text> Get property (exampleproperty)

That way, if it is equal to one, it will broadcast example1, so on and so forth.

1 Like

No, here’s an example of what it looks like in python:

Define the function:

def rand_fun(parameter1,parameter2){
print(parameter1 + parameter2)
}

x = 5
y = 5

rand_fun(x,y)

print(“Done!”)

So in block code, we would start at the x =5 line. Defining the function would take place outside the trigger. After this, we assign y=5. Then, we assign parameter1 as x and to start the function, parameter2 as y. We will now exit the trigger. When the function is finished, it will change the counter property and start the trigger we want to run. But now, it tuns the code after the function (print(“Done!”)). Another way to think of it is that the code technically does not depend on the counter property, only the other property it computes with.

1 Like

The remainder function is weird, and you should just use what BlackHole927 put in the comments of it.

However, to make functions, you get some properties that the trigger uses, because it won’t understand your custom properties. When you change the last property, the trigger gets triggered and the function runs and outputs into the output variables.

Does this make sense now?

  • Yes
  • No
0 voters

I am so sorry, could you explain it again, and with pictures from Gimkit? My brain is not comprehending this.

same, i’m confused.

I don’t get how to use pictures to explain this, but I will detail the order of events.

  1. Property to run the block we want to run changes
  2. Block in trigger runs until it reaches the broadcast to run the trigger for the function
  3. Function runs until the end.
  4. Function changes output property, which alerts the counter for the property
  5. Counter changes property that stores whether or not the function called in the block has run or not.
  6. Property’s change trigger the trigger we want to run.
  7. Since the property is now 1, it goes to the next portion of the code.

Can you take a screenshot of what this looks like in Gimkit?