Jump to content
The Dark Mod Forums

Adding arbitrary spawnargs at runtime--good idea?


SteveL

Recommended Posts

Hi guys. Is there any reason not to attach extra spawnargs to entities at runtime? At first glance it looks like a very useful technique, which avoids having loads of global variables and that could even make up for the lack of dynamically-sized containers in the scripting language, but there could be plenty of disadvantages I haven’t thought of.

 

I’ve found I can spawn a target_null or some other entity in my blueroom and then add any keys I want to it, and retrieve the values later. Easy to see how you could implement a variable-length array or dictionary object that way, and pass it between functions.

 

There’s probably no way to recover the memory used of course… but do you think anything else would go horribly wrong if I used that technique in a real map?

Link to comment
Share on other sites

No idea. But I can't see why you would attach stuff to an entity, rather than simply have a mapname.script and use global variables in there.

 

It is easier to troubleshoot if you have it all in a single script file.

 

Here is an example of a loot cache I made long time ago:

http://wiki.thedarkm...Loot#Loot_Cache

Clipper

-The mapper's best friend.

Link to comment
Share on other sites

Hi Sotha. Thanks for the link, nice idea :)

 

I would still be using a map script to do the above. The "data container" entity would be populated by the script. The advantage of using the technique I was asking about is that you don't need to know in advance how many global variables you need, and the final code will be shorter.

 

Made up example: say I wanted to keep track of which AIs had passed through a trigger so I could make them all drop down dead (or whatever) later. I don't know when writing the code how many will do it, so I don't know how many global variables would be needed. I might also want to store some extra info like when they did it or in what order. Rather than create a set of global variable flags for each and every AI in that part of the map, I could just have the trigger fire a script that stores some info in the trigger:

 

void main()
{
  mytrigger.setKey("ai_count", "0");
}
void mytrigger_activated(entity someAI)
{
  float num_ais = mytrigger.getFloatKey("ai_count");
  num_ais++;
  mytrigger.setKey("ai_count", num_ais);
  mytrigger.setKey("tracked_ai"+num_ais, someAI.getName());
}

 

Then later on, I can just cycle through all the tracked_ai1 ...2 ...3 keys and retrive the list of AIs that had passed through the trigger in order. And any other info about it that I want to store in there.

Edited by SteveL
Link to comment
Share on other sites

If you use a single entity for each container you should get the memory back by simple erasing the entity (void remove() or so). Adding spawnargs during runtime shouldn't cause any problems.

FM's: Builder Roads, Old Habits, Old Habits Rebuild

Mapping and Scripting: Apples and Peaches

Sculptris Models and Tutorials: Obsttortes Models

My wiki articles: Obstipedia

Texture Blending in DR: DR ASE Blend Exporter

Link to comment
Share on other sites

To be honest I do this a lot. I didn't find it a big resource hog & it's a simple & intuitive way to do things. You can define the spawnargs either in a .def file or with a script (if conditional), and then over the course of the game scripts can get or modify them as needed.

 

Edit: You could even think of entities as a natural unit of a system. This is how our brand of Location_Settings started, using the existing LS entity as a hub to drop useful location-sensitive spawnargs into, and then have a script attached to that, so it became a more developed location system in itself. So now dropping the entity into your level is a way to boot up the system in the level; it's intuitive like that. That's one way I think about it anyway.

What do you see when you turn out the light? I can't tell you but I know that it's mine.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • nbohr1more

      The FAQ wiki is almost a proper FAQ now. Probably need to spin-off a bunch of the "remedies" for playing older TDM versions into their own article.
      · 1 reply
    • nbohr1more

      Was checking out old translation packs and decided to fire up TDM 1.07. Rightful Property with sub-20 FPS areas yay! ( same areas run at 180FPS with cranked eye candy on 2.12 )
      · 3 replies
    • taffernicus

      i am so euphoric to see new FMs keep coming out and I am keen to try it out in my leisure time, then suddenly my PC is spouting a couple of S.M.A.R.T errors...
      tbf i cannot afford myself to miss my network emulator image file&progress, important ebooks, hyper-v checkpoint & hyper-v export and the precious thief & TDM gamesaves. Don't fall yourself into & lay your hands on crappy SSD
       
      · 7 replies
    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 7 replies
    • Ansome

      Turns out my 15th anniversary mission idea has already been done once or twice before! I've been beaten to the punch once again, but I suppose that's to be expected when there's over 170 FMs out there, eh? I'm not complaining though, I love learning new tricks and taking inspiration from past FMs. Best of luck on your own fan missions!
      · 4 replies
×
×
  • Create New...