Beginner - Function Help Request

I am trying to create a simple function called “CreateRandomGarbage” that takes three actions and turns them into a callable function.

The three actions are:

  1. Create object Garbage (sprite) at random position…
  2. Change height
  3. Change width

I tried to follow a GDevelop YouTube tutorial on functions and expressions and the documentation as well. It mentioned parameters, but my inputs are static and not dynamic so I don’t need parameters (?). I made my Garbage (sprite) object global in an attempt to get the function/extension to “see” it but that didn’t help.

Can someone help me figure out how to create a simple function with three static actions (or two, I could just use the scale action instead of height + width separately)?

This is a very basic prototype game to help me understand solid, draggable, physics2, and “snap” behaviors:

I am restricted to one embed so I chose the image that has the three actions I’m trying to convert to a function.

Thank you!

*Edit to add: I want to create about 9 random garbage objects when I load/reset the scene. This is the reason for wanting to make a function. Not sure why I spaced this part!

You need to use parameters. Functions are meant to be self-contained. You can’t access objects through regular GDevelop events without using a parameter. They’re designed to be usable in any scene or any project.They behave the same as regular event.

GDevelop can extract the events into functions. They might not be setup exactly the way you want them but they’ll be close. You can then make any changes.

https://wiki.gdevelop.io/gdevelop5/events/functions/

https://wiki.gdevelop.io/gdevelop5/events/functions/extract-events/#extract-events-to-a-function

1 Like

Go to the blue button on the right and jump on it until sky change to night and you will see stars

2 Likes