Ceres' Lua Problems
Moderator: Forum Moderators
Ceres' Lua Problems
One thing that bugged me using [floating_text], is that it's not possible to set any colour. So I just went ahead and modified the tag, so that you may set green, red or blue text colour. The problem is, when qouting the span color part, 'text' is no longer recognized as a variable. Is there any way to solve this?
Code: Select all
function wml_actions.floating_text(cfg)
local locs = wesnoth.get_locations(cfg)
local text = cfg.text or helper.wml_error("[floating_text] missing required text= attribute")
local color = cfg.color
if color == "red" then
for i, loc in ipairs(locs) do
wesnoth.float_label(loc[1], loc[2], "<span color='#ff0000'>text</span>")
end
elseif color == "green" then
for i, loc in ipairs(locs) do
wesnoth.float_label(loc[1], loc[2], "<span color='#00ff00'>text</span>")
end
elseif color == "blue" then
for i, loc in ipairs(locs) do
wesnoth.float_label(loc[1], loc[2], "<span color='#0000ff'>text</span>")
end
end
end
Last edited by Ceres on July 3rd, 2011, 6:33 pm, edited 1 time in total.
Co-Creator of The Fellowship of the Clay (BfW 1.10) ~~ Maintainer of the German Code of Conduct
How to isolate problematic WML code ~~ WML error messages and their reasons
How to isolate problematic WML code ~~ WML error messages and their reasons
- Alarantalara
- Art Contributor
- Posts: 786
- Joined: April 23rd, 2010, 8:17 pm
- Location: Canada
Re: Making [floating_text] recognize color
String concatenation of course:
Code: Select all
"<span color='#ff0000'>"..text.."</span>"
- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Making [floating_text] recognize color
You just need to use Pango markup, without modifying the tag:Ceres wrote:One thing that bugged me using [floating_text], is that it's not possible to set any colour.
Code: Select all
[floating_text]
text= _ "<span color='red'>My text</span>"
x,y=$unit.x,$unit.y
[/floating_text]
Code: Select all
string.format("<span color='#ff0000'>%s</span>", text)
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Re: Making [floating_text] recognize color
Such a simple solution. Thanks to both of you.
Co-Creator of The Fellowship of the Clay (BfW 1.10) ~~ Maintainer of the German Code of Conduct
How to isolate problematic WML code ~~ WML error messages and their reasons
How to isolate problematic WML code ~~ WML error messages and their reasons
Re: Ceres' Lua Problems
Here we go with another one.
That code is supposed to get all units in a radius of 8 hexes around a hex, and move all of them one step towards this hex, if possible (they are pulled towards the centre of a circle).
Upon firing, I get this output: <Lua Error> [string "..."]:6: malformed number near '1..'
(Be warned, my Lua knowledge is based on a quick tutorial and reading code, so don't hit me if the mistake is just made up code, syntax mistakes and such.)
That code is supposed to get all units in a radius of 8 hexes around a hex, and move all of them one step towards this hex, if possible (they are pulled towards the centre of a circle).
Upon firing, I get this output: <Lua Error> [string "..."]:6: malformed number near '1..'
(Be warned, my Lua knowledge is based on a quick tutorial and reading code, so don't hit me if the mistake is just made up code, syntax mistakes and such.)
Here's the Lua snippet:
And here's the whole event including the Lua snippet, if anyone's interested:
Co-Creator of The Fellowship of the Clay (BfW 1.10) ~~ Maintainer of the German Code of Conduct
How to isolate problematic WML code ~~ WML error messages and their reasons
How to isolate problematic WML code ~~ WML error messages and their reasons
Re: Ceres' Lua Problems
For one thing, it's
[u]helper[/u].get_variable_array
, and you'll need to load the helper library to use it.Re: Ceres' Lua Problems
Well, IIRC it depends which variable you load the helper library, but as a convention, that variable is generally named helper (it's simpler). If you wanted, you could name it anything, however.
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
Current projects: Internet meme Era, The Settlers of Wesnoth
Re: Ceres' Lua Problems
I was referring to it by the name used in the documentation. I rarely use those names in practice, typically aliasing them to something shorter, like
gvar()
instead of wesnoth.get_variable()
.- Elvish_Hunter
- Posts: 1575
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: Ceres' Lua Problems
Well, let's see what happens at the Lua interactive prompt when attempting to concatenate numbers and strings:Ceres wrote:Upon firing, I get this output: <Lua Error> [string "..."]:6: malformed number near '1..'
Code: Select all
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> return "test" .. 12 .. "try"
test12try
> return "test"..12.."try"
stdin:1: malformed number near '12..'
> return "test"..12
test12
> return 12.."try"
stdin:1: malformed number near '12..'
> return 12 .. "try"
12try
Code: Select all
wesnoth.set_variable ( string.format( "altar_goto[%d].x", i-1 ), altar_path[i].x )
Code: Select all
[set_variable]
name=range_counter
value=1
[/set_variable]
[set_variable]
namr=range_counter
add=1
[/set_variable]
Code: Select all
local number = wesnoth.get_variable "range_counter.length"
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Re: Ceres' Lua Problems
Thanks everyone, I fixed these mistakes and some additional ones caused by an error in reasoning.
Now the engine complains "bad argument #1 to 'find_path' (expected number, got table)".
Now the engine complains "bad argument #1 to 'find_path' (expected number, got table)".
Lua code
whole code
Co-Creator of The Fellowship of the Clay (BfW 1.10) ~~ Maintainer of the German Code of Conduct
How to isolate problematic WML code ~~ WML error messages and their reasons
How to isolate problematic WML code ~~ WML error messages and their reasons
Re: Ceres' Lua Problems
wesnoth.find_unit
expects either a proxy unit or a pair of coordinates as its first argument; altar_victims[i]
is a cfg dump, not a proxy unit. Change wesnoth.find_unit(altar_victims[i], ...)
to wesnoth.find_unit(altar_victims[i].x, altar_victims[i].y, ...)
.Re: Ceres' Lua Problems
Thanks 8680 (though I suspect you mean find_path, right?).
Almost there, but only almost: while altar_goto.id is set correctly, altar_goto.x and .y aren't. Why? How are the path coordinates output?
Almost there, but only almost: while altar_goto.id is set correctly, altar_goto.x and .y aren't. Why? How are the path coordinates output?
Co-Creator of The Fellowship of the Clay (BfW 1.10) ~~ Maintainer of the German Code of Conduct
How to isolate problematic WML code ~~ WML error messages and their reasons
How to isolate problematic WML code ~~ WML error messages and their reasons
Re: Ceres' Lua Problems
I reread your code (at least the Lua), and I don't see why you're using
wesnoth.find_path
at all; it returns a path, like what [move_unit]
takes (not quite the same, I don't think...); if you already know the destination coordinates, just set altar_goto[i].x
and .y
to them directly. Actually, if the destination is constant, why use a variable at all?
Yes, yes I did.Ceres wrote:(though I suspect you mean find_path, right?)
Re: Ceres' Lua Problems
They're supposed to go only one step towards this point.
(I could try to set moves of all units in range to 1, then set the goto, and after they moved reset the mp, but now I want to finish this shiny code I started with)
So how to extract the coordinates of the first hex of the path?
(I could try to set moves of all units in range to 1, then set the goto, and after they moved reset the mp, but now I want to finish this shiny code I started with)
So how to extract the coordinates of the first hex of the path?
Co-Creator of The Fellowship of the Clay (BfW 1.10) ~~ Maintainer of the German Code of Conduct
How to isolate problematic WML code ~~ WML error messages and their reasons
How to isolate problematic WML code ~~ WML error messages and their reasons
Re: Ceres' Lua Problems
Try
1
instead of i
as the index of altar_path
in wesnoth.set_variable()
.