View Full Version : Colored text in LUA
Larhalt
December 15th, 2015, 09:08
Hello, I'm trying to modify the color of a text in lua
I found out in FG code that the /emote command do what I need, but I'm not able to recreate it.
chat_chat.lua
if dragtype == "skill" or dragtype == "proficiency" or dragtype == "surprise" then
if total <= saveobj then
result_str = " (su " .. saveobj .. ") [SUCCESSO]";
result_str.font = "success";
else
result_str = " (su " .. saveobj .. ") [FALLITO]";
end
end
graphics_fonts.xml
<font name="success">
<fgffile name="graphics/fonts/regular-10.fgf" />
<color value="#a51f21" />
</font>
When I execute the code I have this error in console
Runtime Notice: Reloading ruleset
Script Error: [string "scripts/chat_chat.lua"]:265: attempt to index local 'result_str' (a string value)
Moon Wizard
December 15th, 2015, 09:43
When you assign result_str on the 3rd line shown above, you are making that variable into a string value.
When you attempt to use .font on the end of the variable on the 4th line above, you are treating it like a table value (which is what the error is saying (i.e. it can't look up the table index in a string value)).
I have no idea where you are trying to put the output text and font. I'm assuming that you are eventually trying to call deliverMessage. If so, then you need something like this. Note: This will probably not do exactly what you want, but will get you closer.
local msg = {};
if dragtype == "skill" or dragtype == "proficiency" or dragtype == "surprise" then
if total <= saveobj then
msg.text = " (su " .. saveobj .. ") [SUCCESSO]";
msg.font = "success";
else
msg.text = " (su " .. saveobj .. ") [FALLITO]";
msg.font = "failure";
end
end
deliverMessage(msg);
Regards,
JPG
Larhalt
December 15th, 2015, 10:00
Thank you MW, now the string is red, but there's a problem with the output.
This line
result_str = " (su " .. saveobj .. ") [SUCCESSO]";
Make this output
Strength [8] (su 18) [SUCCESSO]
With the code provided, I don't have anymore the roll result
Moon Wizard
December 15th, 2015, 17:55
If you're working inside onDiceLanded, you'll need to use lines like the following to pull the dice and modifier data from the drag object passed into onDiceLanded.
msg.dice = draginfo.getDieList();
msg.diemodifier = draginfo.getNumberData();
Also, you can add msg.dicedisplay = 1 if you want the total to display.
JPG
Larhalt
December 15th, 2015, 18:32
Thank you again MW, it's seems that working fine now, just the last problem is this one
As you can see, I have two times the result in two different raw.
Moon Wizard
December 15th, 2015, 18:57
You will need to "return true" from the onDiceLanded command to prevent the default processing.
JPG
Larhalt
December 15th, 2015, 22:01
I'm sorry MW, but I can't understand where I have to place the "return true". I've tried everywhere in the function, but it isn't working.
Moon Wizard
December 15th, 2015, 23:23
It depends on whether you are building on top of CoreRPG or not.
If you are not, then using "return true" at the end of your onDiceLanded special handling when you don't want the default processing.
If you are using CoreRPG, you need to register a resultHandler and return true there. (similar to ActionAbility script in 3.5E ruleset)
Regards,
JPG
Larhalt
December 16th, 2015, 09:20
Ok, I tried to understand your tip, but my programming skill is useless as a fish with legs.
I don't think that this ruleset is based on CoreRPG, but I don't know where I can check it
I tried for 1 hour where I can put the "return true" but wherever I place it, I get errors or blank row in the chat
That's the blank row
local msg = {};
if dragtype == "skill" or dragtype == "proficiency" or dragtype == "surprise" then
if total <= saveobj then
msg.text = " (su " .. saveobj .. ") [SUCCESSO]";
msg.font = "success";
else
msg.text = " (su " .. saveobj .. ") [FALLITO]";
msg.font = "failure";
end
return true
end
deliverMessage(msg);
I'd like to attach the entire chat_chat.lua file, but the forum said that are too man characters
damned
December 16th, 2015, 10:55
Ok, I tried to understand your tip, but my programming skill is useless as a fish with legs.
I don't think that this ruleset is based on CoreRPG, but I don't know where I can check it
I tried for 1 hour where I can put the "return true" but wherever I place it, I get errors or blank row in the chat
That's the blank row
local msg = {};
if dragtype == "skill" or dragtype == "proficiency" or dragtype == "surprise" then
if total <= saveobj then
msg.text = " (su " .. saveobj .. ") [SUCCESSO]";
msg.font = "success";
else
msg.text = " (su " .. saveobj .. ") [FALLITO]";
msg.font = "failure";
end
return true
end
deliverMessage(msg);
I'd like to attach the entire chat_chat.lua file, but the forum said that are too man characters
do a find in files for skill or proficiency or surprise and you should find the function (or you might have to find 3 functions)...
i think so anyway...
Larhalt
December 16th, 2015, 11:53
I found three function
In this case, there's already the "return true"
function onDiceLanded(draginfo)
if draginfo.isType("fullattack") then
ModifierStack.setLockCount(draginfo.getSlotCount() );
for i = 1, draginfo.getSlotCount() do
draginfo.setSlot(i);
processDiceLanded(draginfo);
end
return true;
elseif draginfo.isType("attack") or draginfo.isType("critconfirm") or draginfo.isType("damage") or draginfo.isType("init") or
draginfo.isType("save") or draginfo.isType("skill") or draginfo.isType("proficiency") or draginfo.isType("surprise") or draginfo.isType("dice") then
processDiceLanded(draginfo);
return true;
end
end
If I use the "return true" in one of these, I get no print in console
local saveobj = draginfo.getNumberData();
if dragtype == "save" or dragtype == "skill" or dragtype == "proficiency" or dragtype == "surprise" then
draginfo.setNumberData(0);
end
if dragtype == "skill" or dragtype == "proficiency" then
saveobj = saveobj + draginfo.getNumberData()
draginfo.setNumberData(0);
end
Larhalt
December 25th, 2015, 12:04
Hi guys, I'm still trying but without success until now :(
Powered by vBulletin® Version 4.2.1 Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.