adding to existing structs info

This is a moderated forum that collects tutorials, guides, and references for creating Transcendence extensions and scripts.
Post Reply
relanat
Militia Commander
Militia Commander
Posts: 436
Joined: Tue Nov 05, 2013 9:56 am

Thu Aug 10, 2017 5:58 am

The function list in 1.8a2 gives this:

([email protected] struct-var key value) -> struct
([email protected] struct-var struct) -> merged structs

We create a struct by using the format of the first example above.

See this topic for background info https://forums.kronosaur.com/viewtopic. ... ing#p71505

Code: Select all

(typSetData 0xD7892102 'storedItems
	([email protected] (typGetData 0xD7892102 'storedItems)
		"keyName"
		(objGetItems gPlayership '*I~w)
	)
)
where the the struct-var is (typGetData 0xD7892102 'storedItems),
the key is "keyName", and
the value is (objGetItems gPlayership '*I~w).

Using:

Code: Select all

(typGetData 0xD7892102 'storedItems)
shows us this struct for the Scorpion GodPlayership (shield, cargo hold, reactor, drive and 4 armor segments):

{ keyName:((1851399 33554433) (16650 50331649) (16461 67108865) (16505 83886081) (1851393 1) (1851393 16777217) (1851393 33554433) (1851393 50331649)) }


To add to this struct without overwriting it we use the following format. Here we will add the two IDs in the cargo hold.

Code: Select all

(typSetData 0xD7892102 'storedItems
	([email protected] (typGetData 0xD7892102 'storedItems)
		keyName
		(append (@ (typGetData 0xD7892102 'storedItems) keyName)
			(objGetItems gPlayership '*U)
		)
	)
)
giving

{ keyName:((1851399 33554433) (16650 50331649) (16461 67108865) (16505 83886081) (1851393 1) (1851393 16777217) (1851393 33554433) (1851393 50331649) (16470 -16777215) (16583 -16777215)) }
This is the same list with two items added onto it within the 'value' section.
We are using the same code to create the same struct but are 'append'ing the extra two items onto the 'value' list inside the 'value' area of the code.

Trying to merge two structs with the same 'key', here "keyName", using "([email protected] struct-var struct)" results in one struct overwriting the other.

Post Reply