Mqtt retain flag (sharing my solution)

For the 3-4 people using the mqtt extension…

I noticed that topics previously set were not being updated to clients who had just joined/rejoined. The issue is that unless a topic message is flagged as “retain”, the server will assume new clients would rather wait for a fresh update that see the last entry. This made things like setting usernames and game IDs troublesome, as new clients couldn’t see them unless they were re-updated.

The solution is to add a “retain” flag to the mqtt extension. Here’s how i did it:
First, in the mqtt “edit extension options”, go to the “publish” settings and add “retain: eventsFunctionContext.getArgument(“retain”),” just before the qos option.

Then, in the “parameters” tab, add a new parameter named “retain” with the type true/false boolean, and the label “retain”.

Finally, in the configuration tab, add to the sentence in events sheet “Retain: (underscore)PARAM3(underscore)” inside the parenthesis just before the qos.

Note: I made retain as parameter 3. If you add it to the end of the parameters as parameter 4, you’ll just need to name it (underscore)PARAM4(underscore) instead in the sentence.

If you do the above, it will add a “retain” button in the publish options, that will let you choose whether the message will be retained and pushed out to new users.

I’m having an absolute ball with mqtt and am working with a group of students to create a school-wide social deduction (among us-like) game with gdevelop with each kid just grabbing whatever device they have handy to connect to a gdevelop webpage. Very fun.


Thanks for posting this!
Might be interesting to add in the “official” extension @arthuro555?

Sure. I don’t know though if it should be a flag like this or another action “Send persistent event”

I’ve updated the MQTT extension to add this and other stuff, you can find the update and changelog on the GDevelop extensions Trello. It will hopefully be published to the extensions store soon.

1 Like

You ROCK! My son and I have spent the entire school holidays working on a social deduction game to be played across his school with gdevelop/mqtt.


Uhoh. I switched to a non-anonymous mqtt server and realized you’d changed the login information to JSON format. I haven’t been able to wrap my brain around how it should be formatted. From the example I tried {“Username”: login “Password”: password} but that doesn’t look right (or work). Can you please give me an example of a json formatted login and password?

updated to try without the slashes shown in the sample to {“username”: “login”, “password” : “password”} still no luck…

Ok, I’m a big dummy. so a working json for login and password is {/“login/”: /“mylogin”/", /“password/”: /“mypassword”/"} This forum probably won’t show it so each quote mark needs a forward slash in front of it.

(the description in the extension was a tad misleading since clientID and Username are different things… but also i’m a big dummy)

Ah yes sorry, I thought the Setting_* expressions were a bit confusing and that it was too tedious to add all options, and making it JSON would be easier. You can also make a structure variable “options” with all your options in it an use the ToJSON(options) Expression if that helps you.

JSON seems fine, i was just thrown since I had only gotten used to the other system. ( I’m basically a gui noob trying to do overly complicated stuff… and thrilled that gdevelop lets me) For the more nooblike such as me, what do you think of the example text being {/“login/”: /“mylogin”/", /“password/”: /“mypassword”/", /“userId/”: /“myuserid/”} as those seem to be the big three needed?