Help with bad logic syntax

Help with bad logic syntax

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

Help with bad logic syntax

Post by bobthedinosaur »

Okay I am messing around with this to delete every unit but the unit defined as the local watchers UnitDefNames.testor.id when they only ones remaining are the does not counts.
http://sl.pastebin.com/4NM14Mim

Playing with it I can either get it to delete them all including the watchers, or nothing at all.

What am I doing wrong?
Last edited by bobthedinosaur on 12 Oct 2010, 06:37, edited 1 time in total.
User avatar
SpliFF
Posts: 1224
Joined: 28 Jul 2008, 06:51

Re: Help with bad logic syntax

Post by SpliFF »

Well the first thing you're doing wrong is mixing your words into utter nonsense. I've never seen any sentence structure like "when they only ones remaining are the does not counts" before so any possible meaning it might have is totally lost on me.

You better start by explaining what you are trying to do in something closer to English grammar. I'm not being a Nazi about it, I'm honestly baffled.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Help with bad logic syntax

Post by knorke »

bobthedinosaur wrote:Playing with it i can either get it to delete them all including the watchers, or nothing at all.
What am I doing wrong?
Based on "it delets all or nothing at all" it would guess this:

Code: Select all

if Spring.GetUnitDefID(u) ~= watchers then
Spring.DestroyUnit(u, false, true)
end
does not correctly recognize if a unit is a to be deleted or not.

(I do not understand what

Code: Select all

UnitDefNames.testor.id
means.) I think it might be something like you are comparing a DefID (number) to a name (string)
Instead of DefIDs you could try comparing names.

So try something like:

Code: Select all

unitname_not_to_delete = "watcherunit"

in the loop:

for _,u in ipairs(Spring.GetTeamUnits(t)) do
	if (delete_this_unit(u)==true then
		Spring.DestroyUnit(u, false, true)
	end
end


function delete_this_unit (u)
local unitDef = UnitDefs[u]
if (unitDef.name == unitname_not_to_delete) then return false else return true end
end
But really you would better explain your problem more clearly I have no idea if I understood correctly what you want :shock:
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Re: Help with bad logic syntax

Post by bobthedinosaur »

Sorry, the "doesnotcount" are a custom param, I thought some people would recognize from kdr's doesnotcount gadget, that this gadget was originally.

Anyhow, I have a unit "testor", and when it is left with only other units that are does not count, I want the team to be marked for deletion and then delete all of the "doesnotcount" units, but not the "testor" unit.


knorke what are you trying to do with that last unlocalized function?

edit:

I added a custom para to the camera unit aka "testor" or old local watchers. But apparently I am doing this very wrong:
http://sl.pastebin.com/ESra6Dfd
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Help with bad logic syntax

Post by knorke »

knorke what are you trying to do
trying to do this:
Anyhow, I have a unit "testor", and when it is left with only other units that are does not count, I want the team to be marked for deletion and then delete all of the "doesnotcount" units, but not the "testor" unit.
with that last unlocalized function?
didnt think about local/not local or synthax just the general idea.
SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Help with bad logic syntax

Post by SirMaverick »

bobthedinosaur wrote:I added a custom para to the camera unit aka "testor" or old local watchers. But apparently I am doing this very wrong:
You can't copy&paste a body of a function and expect it to work in the same way (your DestroyUnit() is never executed).
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Re: Help with bad logic syntax

Post by bobthedinosaur »

I wasn't exactly copy pasting. It works now, kind of. It just conflicts with other gadgets, not error wise, but action wise.

edit:
Here is what I have now: http://sl.pastebin.com/eK8c8KY5
Unfortunately I think the dead team sticks, because if a round is won and new units spawn for the new round they are deleted right away.

So I am going to have to find out how to kill the bad team after it has done it's job, so it doesn't eat the next round's units.
Post Reply

Return to “Lua Scripts”