How to get a Widget to unitcreated

How to get a Widget to unitcreated

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

Moderator: Moderators

Post Reply
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

How to get a Widget to unitcreated

Post by bobthedinosaur »

If I want a widget that runs on a unitcreated trigger how do I go about doing that, since unit created is synced and widgets are not?
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: How to get a Widget to unitcreated

Post by Niobium »

widget:UnitCreated(...)

Voila. Widgets aren't limited to unsynced callins or callouts. They just can't use functions which change synced data, i.e. SetUnitPosition, but they have no trouble reading the sycned data, i.e. GetUnitPosition, or using some of the synced callins, i.e. :GameFrame, Unit_____, etc.
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Re: How to get a Widget to unitcreated

Post by bobthedinosaur »

Then I must be doing something wrong.
http://sl.pastebin.com/HY37GTR2

Probably with the list?
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: How to get a Widget to unitcreated

Post by aegis »

Spring.SelectUnitArray{unitArray[1]}
you don't want curly braces there, you want parentheses
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Re: How to get a Widget to unitcreated

Post by bobthedinosaur »

they didn't really help either. Plus that code works just fine from where I ripped it from.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: How to get a Widget to unitcreated

Post by Niobium »

SelectUnitArray takes a unit array, so you would use: 'Spring.SelectUnitArray(unitArray)'.
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Re: How to get a Widget to unitcreated

Post by bobthedinosaur »

Ah yes. You are correct. That makes it work just fine.
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: How to get a Widget to unitcreated

Post by Pithikos »

They just can't use functions which change synced data
You can use UnitCreated only on your own units right? Or can you read synced data no matter?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: How to get a Widget to unitcreated

Post by knorke »

You can read synced data, ie unit positions but it is limited to what the player sees:
When used in a widget, UnitCreated, UnitDestroyed and similiar callins only "see" what the player sees.
ie your own units, allied units and enemy units that are Created/Destroyed in your LOS.
For spectators, the widget "sees" everything, same for replays.
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: How to get a Widget to unitcreated

Post by Pithikos »

So there isn't a way to use UnitFinished to count some other team's units? Other than using a gadget..
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: How to get a Widget to unitcreated

Post by knorke »

enemy = no, unless the units are always visible or something
allies = yes
you can check if uniteam == local players team, or what do you mean?
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: How to get a Widget to unitcreated

Post by Pithikos »

Well I work on a mod and I want to count the units of the bot(the enemy bot) in a widget. In that way a user can disable and enable it on her/his own preference. So even if all users have the same widget that is located in the mod there isn't a way to use synced read?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: How to get a Widget to unitcreated

Post by zwzsg »

Widget are "helper" scripts, that players are free to grab or code themselves. Since you can have a widget and your opponent not, what widgets can do is severly limited to make sure they won't allow for cheats & exploits. As a typical exemple, if widgets could know about enemy units, then within hour we'd have a widget to display every units on the map, useable in any mod, without opponent knowing about it. That'll ruin all the games!


Gadget are parts of the mod, they can't be removed or added from a mod without making a new mod, and so they are given full power to change the simulation and the gameplay.
Post Reply

Return to “Lua Scripts”