Author Topic: Questions about triggered animation  (Read 15538 times)

0 Members and 1 Guest are viewing this topic.

Re: Questions about triggered animation
Here's an interesting bug:
Code: [Select]
function ShipType:GetSpecificSubsystem (name)
assert (name ~= nil, "ShipType:GetSpecificSubsystem (name) name is nil")

local result = nil
for loop = 1, #self.subsystemList do
local subsystem = self.subsystemList[loop]
if (subsystem:GetName () == name) then
table.insert (g_orientNow, subsystem:GetName ())
table.insert (g_orientNow, "I'M HERE!!!")
result = subsystem
end
end

--table.insert (g_orientNow, "this->"..result:GetName ())
return result
end

self.subsystemList contains a list of subsystems objects (they have a GetName () function).
The loop goes through each of the entries looking for the correct name. 
It finds the correct one ("I'm HERE!!!" gets displayed on the screen so I know it's found it)
Guess what! result is NIL  :confused:
Even if I replace result = subsystem with return subsystem it's still a nil.  Now I know subsystem can't be a nil, because GetName () would have crashed with nil
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Questions about triggered animation
it basically wants a string but got nil for some reason instead. the function 'GetSpecificSubsystem' was simply given a non-string value. just do a type(name) == "string" check at the top of the function to make sure you bail if the input is bad.

another thing to watch out for is that if under any circumstances GetName() returned nil and name also happened to be nil, then the condition would pass and return nil as the result. *

another thing i noticed, since the result defaults to nil, if it goes through the loop and doesnt find a subsystem that matches the name, it will return nil by default.

*cant be nil because assert
« Last Edit: January 07, 2013, 04:24:04 am by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 
Re: Questions about triggered animation
Thing is.. it's finding it!  The two table.inserts are actually displaying.  Not only that it's showing the correct subsystem name that i asked for. Weird.  :wtf:

Think I found it... problem was higher up the chain.  I was looking for two entries (forgot about the second one), it found the first but couldn't find the second
« Last Edit: January 07, 2013, 04:46:36 am by Scooby_Doo »
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 
Re: Questions about triggered animation
Another piece of good news... a subsystem's subsystem will automatically include any rotation from it's parent.  Although I am having a couple problems with thruster glows, first it orientates itself in the opposite direction it's suppose to go, and second it doesn't move to stay in the same position on the subsystem.  It could be I'm just not attaching them correctly.
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 
Re: Questions about triggered animation
Is it possible to do something like this in lua?

Code: [Select]
void doStuff ()
{
}

.
.
.

myData.FunctionName = doStuff
.
.
.
.
myData.FunctionName ()

it won't let me do execute FunctionName().  What i've found out on google about callbacks is mostly connecting it with C/C++
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 

Online Aardwolf

  • 211
  • Posts: 16,384
Re: Questions about triggered animation
Uh... you didn't actually declare it as void doStuff(), did you?

Code: [Select]
myData.FunctionName = function() --[[ implementation go here ]]-- end
...or if you don't want to do it inline

Code: [Select]
doStuff = function()
-- implementation go here
end

myData.FunctionName = doStuff
myData.FunctionName()

Should work too.

Or is myData a userdata? If it's a userdata you can't add custom members like you can with normal lua objects (i.e. tables).

 
Re: Questions about triggered animation
Sorry I forgot an important sentence... is it possible to do it in Lua?

edit: Basically this is what I'm aiming for:

What I want to have the model maker write (each ship class get's it's own set of functions. aka... RegisterBearcat, RegisterBlackWidow, RegisterHellcat....etc)
Code: [Select]
function ShipType:MyShipClassLandGear (isOpening)
            if (isOpening)
                  -- do opening stuff, choose which subsystem group to activate  (for fancy stuff)
            else
                 -- do closing stuff, choose which subsystem group to activate (for fancy stuff)
            end
end

and only have to write this too (same as above, each ship class gets their own):
Code: [Select]
function ShipType:RegisterMyShipClass (stuff.....)
             -- Do subsystem animation registeration (define what is landing gear, thrust vectoring, thrust nozzles...etc)
             
             self:LandingGearFunction = self.MyShipClassLandingGear
end

then just call OpenLandingGear (ship name) via FRED
then the prewritten code (stuff i'm doing now) will automatically handle it via:

Code: [Select]
function OpenLandingGear (name)
            -- Grab the necessary information (ship, triggered group [landing gear], etc....)
            -- theShip is of type ShipType
            theShip:OpenLandingGear (isOpening)
end

That way you don't have to write a massive if-then-else for each ship class.

This whole thing is rather complicated using triggers and ship classes. but it'll allow for not only each type of ship to have it's own information (in fact each ship has it's own data), but more importantly it allows for chaining animations together to make more advanced effects than what the built-in rotation animation can do. 
« Last Edit: January 11, 2013, 11:50:07 pm by Scooby_Doo »
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Questions about triggered animation
a little word of advise: never tell a modder to write script. :lol:

even it ifs something stupid like a list of variables. seriously, they will give you so much flak.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 
Re: Questions about triggered animation
LOL well until I can read subsystem properties, it'll have to do  :p
Also it's mostly just copy and paste.

Also found the answer to my question, buried on googles pages.
Code: [Select]
function ShipType:BearcatLandingGear (opening)
return function (opening)
                                                          -- do stuff here
table.insert (g_animationDebug, "got here!")
end
end
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 
Re: Questions about triggered animation
OMG this was sooo frustrating...

DO NOT DO THIS!
Code: [Select]
SubsystemListType = {
groups = {}
   }

SubsystemListType.__index = SubsystemListType

function SubsystemListType:Create ()
local newEntry = {}
setmetatable (newEntry, SubsystemListType)
return newEntry
end

DO THIS INSTEAD!
Code: [Select]
SubsystemListType = {
       groups = nil
   }

SubsystemListType.__index = SubsystemListType

function SubsystemListType:Create ()
local newEntry = {}
setmetatable (newEntry, SubsystemListType)
newEntry.groups = {}
return newEntry
end

Otherwise EVERY object you create from SubsystemList will have exactly the same "groups". 
I.e.

item1 = SubsystemList.Create ()
table.insert (item1.groups, 1)
table.insert (item1.groups, 2)
table.insert (item2.groups, 666)

both
#item1.groups
and
#item2.groups   

will give you 3!

Each list must be initialized in it's own self.class
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 
Re: Questions about triggered animation
Code cleanup continues... throwing in asserts for validation checking.  Rewrote a ton of stuff for better usage of groups.  Still some things I want to do about them... right now it's a simple chained (one group can activate another group which in turn can activate.....) to where a group can activate a list of groups.  Think not only chained, but branched out animations.

Also I just realized how powerful this could be.... the simple landing gear type will be able to do nuke's

without much difficulty. The hardest part it guessing the right angles and speeds.
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Questions about triggered animation
first rotation i believe is positive 90 degrees. the second is negative 180 and im not sure about the 3rd, i think 90.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

  
Re: Questions about triggered animation
Anyone that was watching this thread, I've posted an alpha version in this thread: http://www.hard-light.net/forums/index.php?topic=83947.0
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"