How to use [floating_text]

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

How to use [floating_text]

Post by Enderlook » January 24th, 2018, 9:30 pm

I'm trying to make a floating text but it seems that it isn't working for me. My idea is to make a floating text similar to the healing one (camera is moved to location, text is spawned, healing sound is played, text is unspawned), but it isn't working, the [scroll_to_unit] and [floating_text] aren't working.

Code: Select all

[event]
	name=side turn
	(....)
	[scroll_to_unit]
		x,y=$units[$index].x,$units[$index].y
		immediate=yes
		for_side=$side_number				
	[/scroll_to_unit]
	[sound]
		name=gold.wav
	[/sound]
	[floating_text]
		x,y=$units[$index].x,$units[$index].y
		text="<span color='#cccc33'>" + $(round($units[$index].abilities.dummyminer.value*{MULT})) + "</span>"
	[/floating_text]
	[gold]
		amount=$(round($units[$index].abilities.dummyminer.value*{MULT}))
		side=$side_number
	[/gold]
[/event]
It doesn't do nothing.

User avatar
SFault
Posts: 479
Joined: November 10th, 2009, 2:21 pm
Location: Esbo, Finland

Re: How to use [floating_text]

Post by SFault » January 24th, 2018, 9:43 pm

Does this work?

Code: Select all

 text="<span color='#cccc33'>" + _ "$(round($units[$index].abilities.dummyminer.value*{MULT}))|" + "</span>"
segmentation fault
EBfW, GtR, Art, Old art

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How to use [floating_text]

Post by Enderlook » January 24th, 2018, 9:58 pm

SFault wrote:Does this work?

Code: Select all

 text="<span color='#cccc33'>" + _ "$(round($units[$index].abilities.dummyminer.value*{MULT}))|" + "</span>"
Sadly no :(. What does "|"?

User avatar
SFault
Posts: 479
Joined: November 10th, 2009, 2:21 pm
Location: Esbo, Finland

Re: How to use [floating_text]

Post by SFault » January 24th, 2018, 10:52 pm

| separates the variable from the following string e.g. "you found 10 $weapon_type|s"

Is the [gold] working alright? It looks like you are doing multiplying with *. I'm no pro but I think you need to store your dummyminer.value into variable and the use multiply={MULT} on it (assuming it's some macro for a number) and then use that variable in the string.

Code: Select all

[set_variable]
  name=dummyminer_value
  multiply={MULT}
[/set_variable]
segmentation fault
EBfW, GtR, Art, Old art

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How to use [floating_text]

Post by Enderlook » January 24th, 2018, 11:24 pm

The multiplying is working because [gold] works (I get the gold each turn). But the floating text doesn't.
Last edited by Enderlook on January 25th, 2018, 1:50 pm, edited 1 time in total.

User avatar
WhiteWolf
Forum Regular
Posts: 370
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to use [floating_text]

Post by WhiteWolf » January 25th, 2018, 9:06 am

What is "round()"? Is it a variable you also want to multiply with...? Or you just want the value to be rounded? It doesn't work this way, if you want to round it, you first need to calculate this value in a WML variable, then use the ceil/floor attributes of the [set_variables] tag.

Or just leave it, why do you expect non-integers? I think this should work without problems:
Also, make sure the variable is inside "" with the text attribute, you don't need to concut it with + signs. (this could also be the problem).

Code: Select all

	[floating_text]
		x,y=$units[$index].x,$units[$index].y
		text="<span color='#cccc33'> $($units[$index].abilities.dummyminer.value*{MULT}) </span>"
	[/floating_text]
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now published!


User avatar
WhiteWolf
Forum Regular
Posts: 370
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to use [floating_text]

Post by WhiteWolf » January 25th, 2018, 9:59 am

Oh, silly me then :D
I still think it should be between ""-s though, maybe that solves it?
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now published!

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How to use [floating_text]

Post by Enderlook » January 25th, 2018, 2:06 pm

WhiteWolf wrote:Oh, silly me then :D
I still think it should be between ""-s though, maybe that solves it?
Sadly, It keeps not working :( . The text doesn't appear.

User avatar
zookeeper
WML Wizard
Posts: 9734
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: How to use [floating_text]

Post by zookeeper » January 25th, 2018, 2:19 pm

You haven't said whether [floating_text] doesn't work, or whether only one very particular complicated way to use [floating_text] doesn't work. There's kind of a huge difference between those two.

Code: Select all

[event]
   name=side turn
   first_time_only=no

   [floating_text]
      x,y=5,5
      text="testing123"
   [/floating_text]
[/event]
Does that work? If it does, then the tag works all right, and you're just using it wrong, somehow. My guess: with very high likelyhood the mistake is in the code you excluded.

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How to use [floating_text]

Post by Enderlook » January 25th, 2018, 2:57 pm

You have right, if I put your code it works, but if I use [floating_text] in my code, it doesn't :(.
But I don't understand why it wouldn't work. The [gold] tag is below the [floating_text] and works, and the [message] tag (just for testing) is above the [floating_text] and also works. The only two tags that aren't working are [floating_text] and [scroll_to_unit].

Code: Select all

#define GET_GOLD MULT
	[if]
		[variable]
			name=units[$index].attacks_left
			greater_than=0
		[/variable]
		[then]
			[message]
				message=$(max(floor($units[$index].abilities.NE_miner.value*{MULT}),1))
			[/message]
			[scroll_to_unit]
				x,y=$units[$index].x,$units[$index].y
				immediate=yes
				for_side=$side_number				
			[/scroll_to_unit]
			[sound]
				name=gold.ogg
			[/sound]	
			[floating_text]
				x,y=$units[$index].x,$units[$index].y
			    text="<span color='#cccc33'>$(max(floor($units[$index].abilities.NE_miner.value*{MULT}),1))</span>"
			[/floating_text]
			[gold]
				amount=$(max(floor($units[$index].abilities.NE_miner.value*{MULT}),1))
				side=$side_number
			[/gold]
		[/then]
	[/if]	
#enddef
Where $units is:

Code: Select all

				[store_unit]
					[filter]
						side=$side_number
						ability=NE_miner
						[filter_location]
							terrain=Mm,Md,Ms,Hh,Hhd,Hd,Ha,*^Vu,*^Vud,Uh,*^Dr,*^Es
						[/filter_location]
					[/filter]
					variable=units
				[/store_unit]	
				{FOREACH units index}

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How to use [floating_text]

Post by Enderlook » January 25th, 2018, 3:12 pm

I discover I can use [unstore_unit] to make a text appear... and it's works. Shall I use this instead??

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How to use [floating_text]

Post by Enderlook » January 26th, 2018, 12:21 am

Note: I update Wesnoth to 1.13.10 and now [floating_text] works :D.

Post Reply