Best way to pass data to GUI

I need to pass bit of data every frame to GUI. What is best way to do that?

Specifically, I want to have arrows pointing in direction of nearby enemies, while player is moving around with camera attached to him.
Shoud this even be done with GUI?

Personally I would do it with game objects without GUI, but for fast GUI communication you have to use a buffer Lua module. Write arrow positions to the Lua module from game script, read arrow positions in gui script.

2 Likes

This is good advice.

You could also post a message containing a list of vector3. It will not be as efficient but maybe it’s enough in your case?

1 Like

Thank you for your answers. While we’re on topic, I’m using global variables to pass data to GUI for stats like player’s current speed and energy. Is there downside to that?

Global variables lead to unpredictable errors, it’s advised not to use them at all.

Is this what is meant by buffer Lua module?

 --inside Lua Module
       
     local value = 0

        function getValue()
        	return value
        end

        function setValue(_value)
        	value = _value
        end

No

return {
  values = {}
}

Then

local buffer_module = require('buffer_module')

-- Set
buffer_module.values[1] = vmath.vector3(0,0,0)

-- Get
print(buffer_module.values[1])
3 Likes

Oh, that looks much simpler.
Thank you very much!

Global variables also have a great deal of overhead when it comes to performance.

1 Like