Module Functions (Universal Functions)

A better way to organize and reuse code is with module functions, a unique type of code that stores a set of functions and variables designed to meet a shared purpose, like managing player money or enemies. Code within module functions can be used by other code.

Before I leave, I want people to complete this guide for themselves and switch it to community-made guides since these are very useful when making long code and it MIGHT have different interpretations. Besides, I want to see the new generation attempt to solve a problem. These are basically functions you can call in each function where the parameters are transferred and changed according to your needs. On that note, see ya!

So, @Billybanana here, after a couple hours of work I made my first breakthrough on this project,
When you place a trigger as you probably know you can make it trigger When receiving on a channel. So, what I did is p placed 2 triggers down and made one just say this,


Then in the other trigger I made code for a System where it opens a popup asking if you want to rematch

image


Then you can re-use the channel to activate that function at any time. Like if you want to check if someone has a higher score than the other when they enter an arena in a Rpg or if you want to check a “Level” system to make sure they are of high enough level.
So, for now, that’s what I have, and I will be working on this until the community comes up with a way to make an actually useful function instead of mine.

@VALUEX:
A function can look like this in block code(in theory):

--creating the function
function add(num1, num2)
   return num1 + num2
end
--calling the function
local x = add(5, 5) --returns the value 10
print(x) --printing to the console

Something like that in theory at least, of course it will be much much more complicated than that. I think we should use properties as they are global and their changes are kept. Functions can be updated through /a/ counter(s). In order to do this we need to save the data like PCP’s. We could also (instead of PCP’s) use text manipulation. We can extract certain data from a point in the string and use it in our function.

The way I did it was a bit simpler from all of that. I took into consideration that a calculator is a function in a way. I created a small addition function using 2 properties, 2 counters, and 4 triggers.
Here is the setup:


All that happens is that the two triggers with wires, when stepped on, increment the counter, that changes the value of the properties, then the middle trigger has all the block code essential to the function.
image
You can now have a function, how?? Well, like this you can broadcast on a channel from another trigger that will then trigger this main trigger and do exactly the same things!

More ideas:
OOP, or objects.

5 Likes

Aw man, literally everyone who knows about actual coding already left… Who am I supposed to ask for an explanation now?

I guess this… is just a function? I mean it just looks like a normal python function to me. I don’t know like anythin about coding though.

Imma work on this in the morning, I have about 5 years of python and 2 of swift and dart under my wing. It would be fun to work on this in gimkit

1 Like

Bump

This is basically my first guide.

You don’t need to bump topics with this recent activity.

1 Like

Okay! Noted for next time. Sorry

What’s it called?

Functions

A function can look like this in block code(in theory):

--creating the function
function add(num1, num2)
   return num1 + num2
end
--calling the function
local x = add(5, 5) --returns the value 10
print(x) --printing to the console

Something like that in theory at least, of course it will be much much more complicated than that. I think we should use properties as they are global and their changes are kept. Functions can be updated through /a/ counter(s). In order to do this we need to save the data like PCP’s. We could also (instead of PCP’s) use text manipulation. We can extract certain data from a point in the string and use it in our function.

The way I did it was a bit simpler from all of that. I took into consideration that a calculator is a function in a way. I created a small addition function using 2 properties, 2 counters, and 4 triggers.
Here is the setup:


All that happens is that the two triggers with wires, when stepped on, increment the counter, that changes the value of the properties, then the middle trigger has all the block code essential to the function.
image
You can now have a function, how?? Well, like this you can broadcast on a channel from another trigger that will then trigger this main trigger and do exactly the same things!

More ideas:
OOP, or objects.

1 Like

I don’t see it, could you link it?

Just noticed that the main topic was edited…with this…kinda…

NOOOOO!!! Where was this mind when I made my first guide?! jk.

Here:

That’s cool, what can use it for in a game?

It was an example of a possible way of creating functions.

getrithekd

I personally feel like your guide was much harder to understand than the way it was explained here. I barely understood the concept in that guide. No offense of course, just I maybe have a smaller brain to comprehending that.

Thanks that helps, but I don’t think this is the same thing as @getrithekd 's guide because you still cant use it as a complex line of code like we are trying to make, still I understand why you could say that

Yeah… It was my first guide. So basically you use if statements to see if the function has been done.

1 Like

You can also make “module properties” by setting a property to a value if property 2 is something, which would allow you to make ~10 module properties with 1 property. (concatenation)

ex:
if property 2 = 1:
set property to 1
if property 2 = 2:
set property to 2
if property 2 = 3:
set property to 3