Tuto for creating a function in GDevelop

Amigo.

  1. You can create and extension with an extension (Edit: Local Variables is better) variable called TempArray (Array) and TempNo (Number)
  2. An action that takes a string (Comma seperated string)
  3. Use the array tools extension to split it and save in TempArray ( Array tools - GDevelop documentation)
  4. Pick a random number between 0 and ChildrenCount-1 and store in TempNo
  5. Return the child at the TempNo

No Js required in the end.

Hi Ansel

Thanks.

It’s the time i try to create an extension with function(s)

When i’ll do that, i’ll inform you of the result.

Thank again, Ansel

A+
Xierra

About the Choose extension, first it was deprecated because we were meant to use Array Tools instead. Then it was removed. But when they made the Community list, they put it in that. Scroll down to the General section.

Hello @Bubble!

I downloaded yesterday this extension
but the problem is an error message which says extension is not correct for my GD version (269)

Thanks.

Xierra

how dumb do they think we are?

I’m developing an extension to integrate Spectre.css; I’ve also created one for Hyperformula.

There are two types of functions:

Those that are Actions, Conditions, or Expressions.

Those that are loaded on launch (the actual functions)

For the latter, you need to create a namespace that starts with: “gdjs.your-extension-name” so they don’t interfere with other extensions.

Then, in each action/condition/expression, you call the one you need.

Example, namespace:

gdjs._SpectreUI = gdjs._SpectreUI || {};

Function:

// CHANGE THE SCALE

gdjs._SpectreUI.setComponentScale = function(targetID, newScale) {

const container = this.allContainers[targetID];

if (!container) return;

const child = container.firstElementChild;

if (!child) return;



// 1. Calculate the scale ratio

const currentScale = container.spectreData.scale || 1;

const ratio = newScale / currentScale;



// 2. Apply the scale to the inner element

child.style.transform = `scale(${newScale})`;

container.spectreData.scale = newScale;



// 3. Adjust the container proportionally

// This avoids having to resize manually after changing the scale

container.style.width = (container.offsetWidth * ratio) + “px”;

container.style.height = (container.offsetHeight * ratio) + “px”;



container.saveCurrentState();

};

The action:

const id = eventsFunctionContext.getArgument(“ID”);

const scale = eventsFunctionContext.getArgument(“Scale”);



gdjs._SpectreUI.setComponentScale(id, scale);


You must use eventsFunctionContext.getArgument(“”) for each action parameter.

w…why spectre.css? how does this help in gdevelop? i wanted to add dear imgui to gdevelop in an extension btw, that would be amazing for debugging. but it was hard

Formatter::RandomWord(“1,2,3,4,5,6,7,8”)

That is 1 thing i hate gdevelop for
If i don’t want to use boolean variables and instead i want to have 1 sprite object with 2 animations and check that object animations instead
I SHOULD BE ALLOWED TO
And NO ONE should remove that possibility

We should teach ppl to use other stuff
But not take away anything if its still working and someone wants to use it

im afraid i dont entirely understand.

When i joined gdevelop
For first 2-3 months i had no idea what variables are
For me they were this super advanced stuff that i will need years to understand
I heard about them in other engines but never understood what they are
So i avoided them for these 2-3 months

How i dealt with stuff in that time frame?
I was making sprite objects and giving them animations
If i needed something to be on or off i gave sprite object 2 animations
And either set it to something or check if its something

THAT was my substitute for boolean variable
Now imagine if at that time someone came in and remove spite objects
Taking away only way with which i knew how to achieve what i want

NO WAY TO ARGUE that variables would be better option
But also NO WAY TO ARGUE someone would need to teach me what they are and how to use them

Now imagine array tools
How many users even know how to properly use arrays?
Heck how many users know what are arrays?
I invite you to help channel on discord to find out

You’re right Amigo. I had actually had this problem a while ago and had forgotten. So, back then, I found the extension in one of my old projects and have been using that.

I’ve tracked down the original github issue Choose Random Number or String given a string of values · Issue #209 · GDevelopApp/GDevelop-extensions · GitHub and here is the download link from that. I have checked it and it works.

https://github.com/GDevelopApp/GDevelop-extensions/files/7313760/Choose.zip

i know how to use arrays (ive never known why array tools is helpful though), and i dont use discord, but i actually do get what you mean. back when i used Clickteam Fusion 2.5, i used counter objects off screen rather than variables, as i just didnt really have much of a need for them unless im storing something across frames…so i just made one. plus counters gave me instant feedback and debugging, so

Hi @Bubble

Thanks a lot.

I am actually studying the creating of functions and expressions. I begin to understand well how it works.

I created a small function to invert a string. I’ll create others next time.

I think i’ll expose later my works on the subject.

A+

Xierra

I should create functions more than i do! im probably just being lazy …and by being lazy …creating more work for myself. My instinct here would be to have an array called choose[] and then ‘pickone’ set to randominrange(0,5) and set the variable to choose[pickone]. This would be straight forward to turn into an extension with number parameters but the tricky thing to do would be having one parameter input as a text and the extension finds and stores the numbers between the brackets by maybe storing each text between commas in an array of arrays numbers[][]and then converting the string ToNumber(numbers[n][0]+numbers[n][1] etc)

I worked a lot with variables a lot as a teenager…coming to this later in life, after no coding whatsoever in between, its been the concept of the picklist that’s been hardest to grasp…when to pick all and for each etc.

The Spectre.css library is very lightweight and comprehensive.

The problem many designers face is that they don’t want to waste time designing buttons, menus, bars, and so on from scratch.

They just want something beautiful and elegant, without having to tweak every single pixel.

There are other advantages: responsive interface, insensitive to resizing (no blurring), SVG image integration (infinite resizing without blurring), and the use of CSS technology for styling or animation.

Another requirement is that I want to be able to use GDevelop to create software or applications.

Example:

Menu and Table in dark mode, and I’ve started working on a Retro mode:

Hi Dave

Thank to you.

The number of values of the list cannot be fixe. I thought to determine the number of values putting a number in first element of the list, like that:

Choose(5,1,2,3,4,5) or Choose(3,1,2,3)

But i am not yet at this stade.

A+

Xierra

Hello everyone

Does anyone know how the return values of a function (or extension) work?
These return values ​​are important for the event calling the function.

Thanks in advance

A+
Xierra

This doc should help:

Hi @davy

Thanks. I finded by myself some time after posting but your link is interessant.

A+

Xierra