View unanswered posts | View active topics It is currently Thu Aug 22, 2019 4:09 am



Reply to topic  [ 12 posts ] 
 Finding the type of an object searching through the modules 
Author Message
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Finding the type of an object searching through the modules
Okay, basically, what I want to do is this.

In a function, I give as argument the PresetName of an Actor (any kind, from AHumans, to ACrabs, to ACRockets). Then, I use the corresponding "CreateActor(x)" method to create it, but the problem is identifying what kind of actor it is. For example, if I type in "Ronin Soldier", I'll want to use the method "CreateAHuman("Ronin Soldier")" since using the other ones will return the error:

Code:
ERROR: There is no Actor of the Preset name "Ronin Soldier" defined in the "All" Data Module!
(In this case, CreateActor("Ronin Soldier") was used)

Now, there are many ways to solve the problem:

-Adding an extra argument with the type of the actor. Simplest solution, but it takes away big part of the simplicity and user-friendliness.

-Creating multiple functions, one for each kind of actor. Another simple solution, and wouldn't take away big part of the simplicity and user-friendliness, but to be honest, I dislike the idea of having multiple functions to do the same thing that only one function could do.

-Error handling. I googled error handling in Lua, but I think it's not possible to catch the error given by the CreateActor(), since the error is "already catched" (i.e., printed in console), though I'm not really sure. Still, handling the error would be a bit more complicated, because what I'd do would be basically catching the error, try with the next CreateActor() method, see if it works, if not, catch the error again, and repeat the process 'till it works. But then the code would be quite messy trying to catch errors on my catched errors. (There's probably easier ways of doing this, but when it comes to Lua I'm pretty illiterate).

-Universal "CreateActor()" function (CreateAnyActor() or w/e, bad at names). For this, I'd basically need to search through all the modules until I get the PresetName given as an argument, then, determine what actor class is it, and after doing so, use the corresponding method. This would be the best solution, specially because it would also allow me to make the function "CreateAnything()", allowing to for example, not limit the function only to Actors, but making it able to create HeldDevices, ThrownDevices, and any kind of MO, really.


So, to begin with, I'd like to know, is it remotely possible to do my last idea? Can I access the information in the modules, looking for some specific data? Or is it completely impossible? If not impossible, what do?

How possible is it to do the error handling thing? Or is it also a helpless idea?

Any other ideas to solve this problem?

Thanks for reading the wall of text :P


Sat May 03, 2014 4:07 am
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 661
Location: Halifax, Canada
Reply with quote
Post Re: Finding the type of an object searching through the modules
For the last solution, this might help. Or it might not, I don't remember what exactly it was used for haha.

As far as I know lua has no good try/catching since it's designed to work with a compiled language which would deal with errors. But I may be wrong, I've never really looked into it, google would probably help you there. Your best bet there might be to check the returned type and if it's nil move on to the next type of actor since CreateAetc. return whatever you created:
Code:
local a;
a = CreateAHuman(...)
if a == nil then --Or if type(a) == "nil" then
   a  = CreateACrab(...)
end
if a == nil then etc.


I'm honestly not sure this'd work though.


Sat May 03, 2014 5:39 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Finding the type of an object searching through the modules
Bad Boy wrote:
For the last solution, this might help. Or it might not, I don't remember what exactly it was used for haha.

As far as I know lua has no good try/catching since it's designed to work with a compiled language which would deal with errors. But I may be wrong, I've never really looked into it, google would probably help you there. Your best bet there might be to check the returned type and if it's nil move on to the next type of actor since CreateAetc. return whatever you created:
Code:
local a;
a = CreateAHuman(...)
if a == nil then --Or if type(a) == "nil" then
   a  = CreateACrab(...)
end
if a == nil then etc.


I'm honestly not sure this'd work though.


Oh gawd!

It worked! Ha! I thought facing errors stopped the execution of the script, but I guess I was wrong (or it doesn't work like that on the latest build).

Thanks for that :D!
:D

:D :D

Though it still prints the error on the console :P
Who cares, it works :D


Sat May 03, 2014 5:50 am
Profile

Joined: Fri Nov 23, 2012 5:42 am
Posts: 143
Reply with quote
Post Re: Finding the type of an object searching through the modules
This is what I use to get the module from an actor (all though it should work with firearms and otherstuff as well). I bet you could modify it to do what you want.

Code:
function Carnage:GetModule(Preset)
--print("getting module")
   for i = 0, (PresetMan:GetTotalModuleCount()-1) do
      Preset.TempModule = PresetMan:GetEntityDataLocation(Preset.ClassName, Preset.PresetName, i)
      local number1, number2 = string.find(Preset.TempModule, ".rte")
      if number2 ~= nil then                  
         local TempModule = string.sub(Preset.TempModule, 1, number2)
         Preset.Module = TempModule
      end
   end
   --print(Preset.Module)
   return Preset.Module
end


Edit: Eh, nvm I'm too late :grin:


Sat May 03, 2014 5:57 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Finding the type of an object searching through the modules
Thanks for replying anyway! I might use that method in the future though, so it wasn't in vain :P


Sat May 03, 2014 5:59 am
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 661
Location: Halifax, Canada
Reply with quote
Post Re: Finding the type of an object searching through the modules
Haha yep, the errors don't actually stop anything, the update script will always get run so the worst case when you're trying to use the in a controlled way is that they make things take another frame. Also they look ugly. Fortunately the newest version has ConsoleMan:ClearConsole(I think there are no arguments) so if you mind it you can clean it :)


Sat May 03, 2014 2:38 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Finding the type of an object searching through the modules
There is??

Ugh, the wiki should be updated more often.


Sat May 03, 2014 7:52 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 661
Location: Halifax, Canada
Reply with quote
Post Re: Finding the type of an object searching through the modules
Haha yeah, I really wish the wiki would be updated. I've had to find all the new stuff (that I've found) by guessing and looking through relevant base.rte code. There're even some nice things from older versions that it makes absolutely no mention of.

This page does have some or a lot of the new lua stuff, including ConsoleMan:Clear(). By the way, correction, it was this not ConsoleMan:ClearConsole() apparently: http://tradestar.datarealms.com/ccbuild30/


Sat May 03, 2014 10:16 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Finding the type of an object searching through the modules
Oh wow, there seems to be a lot of changes, and not only about Lua!

This one is actually interesting:

Quote:
HeldDevice: Loudness (a device is audible from ~Loudness*0.6*playerScreenWidth when activated). Default is 1.0 except tools where the default is 0.5


Does that mean that we can have actual stealthy weapons/actors?

We need a better thread to discuss this :P


Sat May 03, 2014 10:24 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 661
Location: Halifax, Canada
Reply with quote
Post Re: Finding the type of an object searching through the modules
Haha yeah, we do need a better thread, maybe a general discussion on cool lua changes and stuff most people haven't heard of would be a good idea.
And yep, I believe it does, at least in terms of ai. Of course player controlled actors aren't alerted directly but presumably the player will hear or not hear the sound based on the loudness. Either way this does give some potentially awesome opportunities for genuinely silenced and stealthed weapons without resorting to all the kinda messy hitsbymos stuff like in darkstorm and most similar stealth stuff.

I like seeing new options open up to lua, the more useful stuff we can interact with the better. For example, the fact that we now have a completely unique ID to track absolutely any actor with (actor.UniqueID property I think it is) is wonderful in my books :D It makes so much parent checking and all sorts of categorization and validation so so much easier since you just need a number rather than a reference to the actor.


Sun May 04, 2014 8:48 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Finding the type of an object searching through the modules
I was just testing the Loudness variable, it's truly a miracle. Set a handgun with Loudness = 0 to test, you can fire it just besides an opponent actor and it won't detect the shot, unless it's hit of course. Now, it'd be even more interesting if you could be able to apply it to JetPacks or AEmitters directly, that way you could have some real stealth units. I mean, you can do it nowadays making a fake jetpack with Lua, but oh well, you get the point :P

So, actor.UniqueID is differen't from actor.ID? I thought it was gonna be just like an upgrade of the .ID property :P Sounds nice!


Sun May 04, 2014 9:08 am
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 661
Location: Halifax, Canada
Reply with quote
Post Re: Finding the type of an object searching through the modules
Oh wow, that's awesome. Combine that with a bit of clever FOW stuff and you can have some really great stealth stuff without actually going invisible, nice!

Yeah, unique id is great, as the name suggests it's completely unique for every actor (maybe any MO, not sure how far back the property exists). So you can use it in place of an actor reference and avoid any invalid operator issues, or you can use it for parent checks and so on. It's just nice and all purpose.


Sun May 04, 2014 7:45 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.021s | 13 Queries | GZIP : Off ]