Need help understanding Firebase functionalities in GDevelop

Hi there,

I’m reaching out because I’m new to Firebase integration, particularly within GDevelop, and I’m struggling to grasp some of its features. Currently, I’m facing an issue where I need to change a “Field” of a “Document” with a numerical variable. However, I’ve noticed that the Firebase integration in GDevelop only accepts string variables for the Firebase Database.

Could you please provide some guidance or resources on how to handle numerical variables in Firebase within the GDevelop environment? Any help or pointers would be greatly appreciated.

Thanks in advance for your assistance.

Firebase is actually used to store an account and more stuff to your game.Also for mainly login and create account options for games.But for that u need to go to firebase app create a new project and copy that projects link and put in gdevelops firebase place in order for it to work.You go on web in firebase which is like like </> then register your app with nickname and copy a part of the code.

This one and then paste it on the gdevelop place in prperties

Or just go to this place to understand better

1 Like

Thank you, but I already did that step, now i am trying to store a Num Var to the database, i know how to store it but for some reason at field action i can only store a String var and not a Num/Boolean etc.
So i am searching other ways to do it

You can just use the gdevelop storage feature to store a num var

Hi @Kruger,

I believe this is possible with javascript, though I don’t know how. But you can store your variables as strings and convert them back with a simple events.

For numbers:

  • Store the variable using this expression: ToString(Variable(num_var))
  • When getting the field, convert the callback variable and store it in your number variable: ToNumber(VariableString(callback))

For booleans, store as “0” or “1” (or you can use “false” / “true”):

  • if boolean = FALSE → store value “0”
  • if boolean = TRUE → store value “1”

When getting the field, check if the callback is 0 or 1 then set your boolean variable:

  • if callback = “0” → set boolean to FALSE
  • if callback = “1” → set boolean to TRUE

How i can do it? I never did it

Actually i am trying to convert the String Variable of the Firebase and make it a Num, but I don’t really understand how to do it with events

ToNumber() converts a string to a number (the string should already be made up of numbers).

So after you fetch the string and store in a callback variable (let’s say you call it “callback_var”), set your number variable to: ToNumber(VariableString(callback_var))

1 Like

But i need to do this with Js, i can do this with Only events?

Yes normal GDevelop actions, get field and set variable.

1 Like

When i change the variable Candela from String to Number the value becomes always 1. When it goes to the Firebase Database. I have a big issue with “Update the field”

I fixed the issue, now i need to reset the Field everyday automatically, how i can achieve that?

A basic solution would be to save the time when the 24hr starts, then check if the current time > saved time + 24hrs. Use the expression Time(“timestamp”) which gets the device’s current unix timestamp in milliseconds.

Compare numbers: Time(“timestamp”) > saved timestamp + (1000 * 60 * 60 * 24) → reset field

Check this thread with a similar logic:

I understand the logic but If i follow this path the player/user have the reset on his Hardware, while i want a reset on the server (I need to make some multiplayer stuff), so i need to do this thing in Firebase and not in Gdevelop i suppose. Or I am wrong?

I’m sorry I can’t help you with this, I believe this can be done through firestore functions and I’m not an expert with it. I can help you more with stuff related to GDevelop.

Do a quick google search, maybe you’ll find your answer, or you can ask on platforms like stack overflow. Good luck!

1 Like

Dont worry, i know now how to do it

I have another issue now i have a Global Structure Variable called “Saves” where is store all User data, but I can’t put this Structure Var in the Firestore Database because there isn’t an expression to take these Var, so what i can do now?