Transfer object between maps

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Transfer object between maps

Post by Apeirogon »

I try to create clip based weapon mechanics.
I create every clip as object "class new_clip {definition;}"

If I remember correctly, all objects, thinkers and actors removes from memory after changing map, if such objects, thinkers and actors was created on previous map.
And now I think "how transfer such object between maps?".
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: Transfer object between maps

Post by gwHero »

Storing info of the actor in global variable(s) and spawn identical actor again when entering the new level is possible.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Transfer object between maps

Post by Apeirogon »

This is the only way, dance around world load/unload events?
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: Transfer object between maps

Post by gwHero »

If I'm well-informed, the player with his inventory is the only actor that is recreated automatically when crossing a level. All others are history :) (except when it's a hub and you go back to the same map, but that's something else).
So I wouldn't know how to do it differently; luckily you can choose between acs global vars and zscript global thinkers (I prefer the latter) to save stuff.
User avatar
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Transfer object between maps

Post by Caligari87 »

Inventory items can have the +INVENTORY.PERSISTENTPOWER flag (explanation: This item is kept when travelling between levels, even outside of a hub). I think ammo and weapons can use this to preserve their custom variables since they're subclasses of Inventory. I use this on the calorie tracker and messkit in HD-Scavenger and it seems to keep everything properly.

8-)
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Transfer object between maps

Post by Apeirogon »

But it count as object. Пzdoom cant save similar items as separated items, only stacking it up.
I mean, gzdoom store multiple "bullet clip" class as "bullet clip: amount in inventory 3/5/7/167841234346", depending of how much times player picked up such item.

Now I have one inventory "clip dummy" inside of which I store and create all ponters to "actual clip" objects, which then used by weapon for shooting/reloading/etc.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Transfer object between maps

Post by Matt »

The way I do it is to have a dynamic array variable on the inventory actor that tracks the amounts on each clip, then create a function that ensures that the dynamic array's size is the same as the actor's amount, then call that function anytime the clip amount information is accessed.

Keep in mind: every inventory on the player is a single actor with an amount defined, so your carrying 1, 20 or 600 cells is just one "Cell" actor that's owned by the player with its "amount" variable set to 1, 20 or 600.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Transfer object between maps

Post by Apeirogon »

Problem is that I try to...too literally transfer clip from real life.
Like, weight, size, volume, density, scrapes and another conditions. Like, some mags wedge after 15 bullets, some can...accommodate 7 bullets, although in technical passport black on white write "capacity eight thousand hundred millions bullets". Plus amount of clip itself, like or ten 30-bullets clip max, or five 50-bullets clip, or one bullet belt with 2000 bullets in it.
I dont know how to check it all from one single item.

Only create hungred of "class clip : base clip.... class clip1 : base clip......" entry in zscript.
Post Reply

Return to “Scripting”