widget:UnitExperience

widget:UnitExperience

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

widget:UnitExperience

Post by very_bad_soldier »

Is there a problem with that callin? I tried to figure out why the rank icons widget is not working (http://widgets.springrts.de/index.php#26). It seems the callin is not getting called. It should be called as soon as a unit is doing damage, right?
The function does not appear on the wiki page (http://springrts.com/wiki/LuaCallinReturn) but I see it in the cpp source (https://github.com/spring/spring/blob/d ... Handle.cpp).

Anyone who could give me a hint whats going on?
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: widget:UnitExperience

Post by Niobium »

From elsewhere in the doc:

Code: Select all

Spring.SetExperienceGrade
 ( number expGrade
  [, number ExpPowerScale [, number ExpHealthScale [, number ExpReloadScale ]]] ) -> nil

 expGrade defines how often UnitExperience() will be called,
  it is based on the following equation:
    (int) [exp/(exp+1)] / expGrade
  If this integer differs from the one before the experience change
  it will call UnitExperience().
 Also those 3 last params are only available in .cheat
Personally I wouldn't use the callin at all, the rank icons widget doesn't seem to use it anyway.

As for why it doesn't work, have you included the images? The widget doesn't do much else
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: widget:UnitExperience

Post by jK »

most recent rank icons relies on an api gadget
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: widget:UnitExperience

Post by very_bad_soldier »

Niobium wrote: Personally I wouldn't use the callin at all, the rank icons widget doesn't seem to use it anyway.
I dont plan to rewrite that widget, but just out of interest: why would you not use that callin? It looks like the perfect thing to know about experience changes.
And to which rank widget are you refering that does not use widget:UnitExperience? Zerok's version uses it as well as the version in the widget DB.
Niobium wrote: As for why it doesn't work, have you included the images? The widget doesn't do much else
Yes images are there. As said the UnitExperience callin not being called was the problem.

Anyway, I got it running now. Major problem was that the UnitExperience callin is not available for widgets by default. ZK managed it my using a modified widget handler as far as I can see.

Thanks gentlemen.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: widget:UnitExperience

Post by Niobium »

very_bad_soldier wrote:
Niobium wrote: Personally I wouldn't use the callin at all, the rank icons widget doesn't seem to use it anyway.
I dont plan to rewrite that widget, but just out of interest: why would you not use that callin? It looks like the perfect thing to know about experience changes.
A widget that used the callin might be more efficient, but it will maintain a lot more variables and have more lines of code (and thus chances of bugs) than one that just got the experience when it goes to draw the rank icon.

My own version of the rank icons widget only has 1 callin, :DrawWorld, which is only 30 lines long. The widget itself is only 80 lines. Contrast this to the zero-k version that uses the :UnitExperience callin approach and ends up with 5 callins and 250 lines - 4x the size it needs to be.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: widget:UnitExperience

Post by jK »

Niobium wrote:My own version of the rank icons widget only has 1 callin, :DrawWorld, which is only 30 lines long. The widget itself is only 80 lines. Contrast this to the zero-k version that uses the :UnitExperience callin approach and ends up with 5 callins and 250 lines - 4x the size it needs to be.
And yours is 100x slower. Short code is nice etc., but sometimes you need to go the hard way and optimize stuff and that costs codelines.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: widget:UnitExperience

Post by Niobium »

jK wrote:
Niobium wrote:My own version of the rank icons widget only has 1 callin, :DrawWorld, which is only 30 lines long. The widget itself is only 80 lines. Contrast this to the zero-k version that uses the :UnitExperience callin approach and ends up with 5 callins and 250 lines - 4x the size it needs to be.
And yours is 100x slower. Short code is nice etc., but sometimes you need to go the hard way and optimize stuff and that costs codelines.
My testing shows they are roughly equivalent. Except when the experienced units are off screen - then zero-k's is the one that is 100x slower as it doesn't factor in visibility and draws for all those offscreen units while mine doesn't.

Different styles for different people, I prefer simplicity over speed, others prefer the opposite, both are valid.
Post Reply

Return to “Lua Scripts”