• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

How can i print a variable in AIO addon

jonmii

Enthusiast
This is the question:

I am using the example AIO window, i modified the Text line, but i wanna add a variable.
How can i do it?
Also, how can i call functions over AIO?

Thanks ^^
 

Rochet2

Moderator / Eluna Dev
By "text line" you refer to "Test" string in the button? Or what exactly do you refer to?
http://i.imgur.com/6Quc3hg.png

What do you mean with how can you call functions over AIO?
Are you asking how to call client API functions from server side? or what is this about exactly?

Also about printing, you can just do print("my value") and it shows in the player chat if executed on client side and on the server console on server side
 

jonmii

Enthusiast
I added in Server.lua file:
function MyHandlers.Nick(player)
local nick = Player:GetAccountName()
end

and in Client.lua i have:
-- Jugadores en cola
local nick = frameAttributes:CreateFontString("nick")
nick:SetFont("Fonts\\FRIZQT__.TTF", 15)
nick:SetSize(137, 5)
nick:SetPoint("TOPLEFT", 15, -150)
nick:SetText("|cFF000000Your nick is: |r" ) <-- Here i want add nick variable here.
 
Last edited:

Rochet2

Moderator / Eluna Dev
You need to code a handler in Client.lua which will receive the account name and set the text for "nick" with it.
You need to code the server to send the nick to the player.

In practice you would need this on client.lua:
Code:
local MyHandlers = AIO.AddHandlers("AIOExample2", {})
function MyHandlers.TheHandler(player, playernick)
    nick:SetText("|cFF000000Your nick is: "..playernick.."|r" ) -- assuming nick is global
end

And this on server side:
Code:
-- this is where you want to send the nick to the player
AIO.Handle(player, "AIOExample2", "TheHandler", player:GetAccountName())


If you want to show something on the player's screen, you need to either know when to send it to the player on server and send it then,
Or you need to first request it from server when you need it and then server sends it.
And then the client receives it and shows it.

There is no easy way of getting something from the server on demand like nick:SetText("Value:"..GetValueFromServer())
The reason this is not possible is that it would either freeze the client for the time to fetch the needed value or it would halt rendering or whatever the client was doing until the value is fetched.
The only nice way I can think of is to get the data on login for example or other known event you can use to send it to player, or you can request it (and maybe have a dummy value at this point), wait for it to arrive and then use it.
 

Tommy

Founder
Why ..playernick.. ?

Because that's how you display the variable so the player can see its string (or other types) value. For example, if you did (without ..playernick..):

Code:
nick:SetText("|cFF000000Your nick is: playernick|r" )

Then the player would only see "Your nick is: playernick", instead of playernick value.
 

jonmii

Enthusiast
Yes, but im not speaking about concatenating, im asking why any variable name work, it broke me the head to know from where appear "playernick" and i noticed that it doesnt matter what name you use.
 

Rochet2

Moderator / Eluna Dev
Why ..playernick.. ?
Because .. it was unused in the code. Shrug. And it was set to the "nick" element.
Could be accountid too if it makes more sense. Its not like the variable name matters in any way.

TheHandler will take in anything the server sends. When you define TheHandler you can define the names of the parameters. I used playernick.

The server sends this: AIO.Handle(player, "AIOExample2", "TheHandler", player:GetAccountName())
So playernick would be what the return value of player:GetAccountName() is.

The server could send more or less stuff.
Then the extra stuff is ignored unless you add more parameters to TheHandler and if less stuff is sent by server then playernick is nil.

If you think about what happens here:
Code:
function test(a)
print(a)
end

test("asd")
You should come to the conclusion that you can change "a" to anything - for example playernick - and the code would work and it does not matter what the parameter is. The code would work even if there were more parameters or if test was called with more arguments or less arguments.
 
Last edited:
Top