Best way to pass data to GUI

#1

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?

0 Likes

#2

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

#3

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

#4

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?

0 Likes

#5

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

0 Likes

#6

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
0 Likes

#7

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

#8

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

0 Likes

#9

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

1 Like