What's new
  • Visit Rebornbuddy
  • Visit Resources
  • Visit API Documentation
  • Visit Downloads
  • Visit Portal
  • Visit Panda Profiles
  • Visit LLamamMagic

Problem with boolean responses with Lua?

Vastico

New Member
Joined
Jul 28, 2011
Messages
424
Reaction score
10
Whenever I try to use Lua to get a boolean return value it always provides me with a blank string or a null value? (Even if the response is meant to be true)

Is there an issue?
 
Bump, could this be answered by a developer please D:
 
what do you use to get the desired value? and what kind of LUA command do you want to do?
AFAIK this is the only way to get some lua answer
Lua.GetReturnValues("return GetRaidRosterInfo('"+index+"')").First();
ofc you have to change that lua command with your command but it alway worked for me (and is working now..)
Maybe what you need is a
bool.Parse(Lua.GetReturnValues("return [INSERT LUA CODE]").First());
 
As glideroy said, then it depends on the command you are using, however, here is the code i usually use for getting return value (note: only for Lua API):

HTML:
Lua.GetReturnVal<int>("GetCurrencyInfo(392)", 1);

(in your case you should ofc use GetReturnValue<bool>, and the '1' should be changed to the argument you want from the API - if your using Lua API)
 
There is a bug in the bool version of Lua.GetReturnVal<bool> where it converts any value to true such as the number 0 or the string 'false' and only if the lua returns nil will it correctly return false. so you will want to avoid using it completely. Bug has existed for over a year and been reported several times.

Alternative methods to get a boolean return include

PHP:
Lua.GetReturnValues("return GetWeaponEnchantInfo()")[0] == "1"
Lua.GetReturnVal<int>("return GetWeaponEnchantInfo()",0) == 1
// if the lua funtion returns 'true'/ 'false' string than use the below examle
Lua.GetReturnValues("return GetWeaponEnchantInfo()")[0] == "true"
 
Last edited:
Code:
bool leader = Lua.GetReturnVal<bool>("return GetLFGRoles()", 0);

Never gives true, when I just use a string it's output is blank when it should always return true or false.
 
but if you do a bool.parse(getreturnvalu()).first()) you avoid the problem since the duty to transform the value to a boolean is handled outside the get return value
vastico have you tried my method?
 
Code:
bool leader = Lua.GetReturnVal<bool>("return GetLFGRoles()", 0);

Never gives true, when I just use a string it's output is blank when it should always return true or false.
Could also do something like this
PHP:
bool leader = Lua.GetReturnVal<int>("if GetLFGRoles() == true then return 1 else return 0 end", 0) == 1;
 
Last edited:
yep, that will put the duty of the check on the LUA itself , but you will need a Cast from the lua.getreturnval<int> and the bool leader
 
Lua.GetReturnValue and related methods return null(Or a blank string. I don't recall) when the lua function returns an actual false/true value. AFAIK there's 3 different boolean values types that lua functions return. the numbers 1 or 0. the strings "true" or 'false' or the actual bool true/false which HB has trouble returning and this is the value type that GetLFGRoles returns. And on some of the lua functions return nil instead of returning 0,'false' or false

The only way to get this to work is to convert it to a value type from lua that GetReturnValue can correctly return . such as a numeric value in my last example.

Also bool.Parse() can only parse the string versions ('true' , 'false', not "1" , "0", or even null ).
 
Last edited:
How do I identify between the values?

The return goes:
Leader, Tank, Heal, Damage

How do I get the return for each with your methods D:?
 
my metod
bool leader=bool.Parse(Lua.GetReturnValues("return GetLFGRoles()")[index]);

Highvoltz metod
bool leader = Lua.GetReturnVal<int>("if GetLFGRoles() == true then return 1 else return 0 end", index) == 1;

index=0 leader
index=1 tank
index=2 heal
index=3 damage
 
Awesome!!
Code:
string luaExecute = String.Format("local Leader, Tank, isHealer, Damage = GetLFGRoles(); if {0} == true then return 1 else return 0 end", type);
            bool result = Lua.GetReturnVal<int>(luaExecute, 0) == 1;  
            Log("Roles: {0}, {1}, {2}", type, result, (uint)type);
Output:
[DungeonBuddy]: Roles: Damage, True, 3
 
Back
Top