Getting backend response and showing different images depending on the response.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jebenipapa

I’ve made a simple game that has a backend structure backing it up. As a finale to my game if the user manages to win I want them to chose between 3 things all having a random server response behind them and givin the user a reward. How can I approach this?
How can I make Godot get the server response and either make a label or show a existing label I’ve made previously depending on the response? Along side this I want to show a different image for each of the rewards which also corresponds to the response I.e. I have a lawnmower, mixer and AC unit as my three obtainable rewards. So if my backend rolls a AC unit I want the user to see. “Congrats u got an AC my dude” and under it an image of the said AC unit.

:bust_in_silhouette: Reply From: r.bailey

So there are a number of ways to do this. You could have the server do simple RNG on the the 3 different values whenever the client sends it what choice(position) they chose. I will link the built-in RNG for the Godot engine below. This should be simple enough to figure out how to set it up if you want to use this route. If you have to create your own, because of how your server is setup, that is on you.

RandomNumberGenerator – Godot Stable

You can then send back the data however you want, a simple way is to send a string of the path name of the image you have in project already. So you can load that into a Type:TextureRect that you set within the scene you want. If you are preloading textures(this is not a simple you would think) you can just pass the object in. If not you need to load the image then pass it in.

var currentimage:Resource = load(stringpathfromserver)

Hope this helps.