spawning with ID

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

spawning with ID

Post by RayB »

I have spawned many items using script. When doing so, an item can be placed precisely in the dungeon using:
'spawn(object, level, x, y, facing, elevation, [id])'
which allows you to specify a unique (optional) ID for the object.

I am trying to change an item's ID. I know of no way to do this without destroying the item and replacing it with a new one with the new ID. However, when the item is spawned into an alcove or other container (I am trying to change the ID of an item I place In an alcove), as far as I know I can only use 'spawn("item").item' and therefore have no way to specify an ID.

Is there any way to spawn an item in a container with a specified ID or better yet, to simply change an item's ID?

I know this can be done using the editor's inspector section but I would like to do it on the fly during the game.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: spawning with ID

Post by minmay »

RayB wrote:as far as I know I can only use 'spawn("item").item' and therefore have no way to specify an ID.

Code: Select all

spawn(object,nil,nil,nil,nil,nil,[id]).item
You cannot change a GameObject's id after it is created, and you definitely shouldn't want to.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: spawning with ID

Post by Isaac »

What [exactly] is the reason for wanting to change the id ~instead of just spawning a new one?
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: spawning with ID

Post by RayB »

To Isaac:
Last winter, thanks to help from minmay, I was able to complete a climb-down/climb-up rope routine. Although summer projects have kept me busy, I have still been tinkering with my mod when I have time.

My thought was for the rope to be climb-down only until the player places it in a special alcove which would turn it into a 'magic rope' adding the climb-up capability.

Recently, I have been contemplating having more then one rope in my dungeon located in different places (as in Grim 2). There are, of course, many ways of handling this. An easy method: when either rope is placed in a special alcove a variable is set allowing the rope routine to treat 'any rope found' as a 'magical' rope. However, I would like to differentiate between the ropes. For example, If a player has a 'magic rope', then later on picks up a second rope, then later on decides he doesn't need two ropes and sets down the wrong one. He will soon find that the rope he kept does not have the climb-up capability. He will then have to locate the special alcove and place the rope in it or go back and trade it with the one he discarded. Of course, like with the single variable method, it would be possible to have two magic ropes. The difference is each one would have to be placed in the alcove.

Therefore, the rope routine must be able to know which rope the player is using. My thoughts were to tack on an 'm' (for magic) to the rope's id when it is placed in the alcove (rope_1 would become rope_1m). The rope routine would then be able to check the rope's id to see if it contained an 'm' and thus allow it to use the climb-up code section.

I have also thought of using a global array whose indices would match the rope numbers and be set to true or false if magical or not.

If there is a better way of handling this I am all ears. However, if these methods are acceptable, I would like to know which one (array or id change) would be the better approach.

Thanks again guys for listening
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: spawning with ID

Post by Isaac »

Is there a reason not to have two different rope objects? One with the name 'rope_magical'? This is easy to detect in scripts. Barring that... what about using the 'gameEffect' variable on two of your rope objects?
gameEffect = "Allows the party to climb upward"
This can be set via script, and checked via script.
RayB
Posts: 140
Joined: Fri Mar 06, 2015 3:45 am

Re: spawning with ID

Post by RayB »

I am not sure about the gameEffect thing but I will check it out. However, the duplicate definition, a 'rope' and a 'magic_rope' sounds like a pretty good plan and my routine could just check the name to see which kind of rope it was dealing with.

Thanks for the suggestions.
Post Reply