Help with lists

Freeform discussion about anything related to modding Transcendence.
Post Reply
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

I was making a list for a mod I'm working on. The code in question is

Code: Select all

(setq charonStationsList (list &stCharonPirateOutpost3; &stCharonPirateOutpost2a;))
It always returns the last item in the list. I tried switching the order, and it still returned the last item. Why is it doing this? I checked a working reference and it doesn't seem to have any errors.
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
Prophet
Militia Captain
Militia Captain
Posts: 826
Joined: Tue Nov 18, 2008 6:09 pm

The example you posted seems fine.

You're saying that the list returned only contains one item, the last one?

Can you paste more of the actual code? Perhaps there is something funny going on in another line.
Coming soon: The Syrtian War adventure mod!
A Turret defense genre mod exploring the worst era in Earth's history.
Can you defend the Earth from the Syrtian invaders?
Stay tuned for updates!
User avatar
Aury
Fleet Admiral
Fleet Admiral
Posts: 5528
Joined: Tue Feb 05, 2008 1:10 am
Location: At the VSS Shipyards in the frontier, designing new ships.

the method you are using for your return may only support one item of the list. I'm not sure, since I can't see it though.
(shpOrder gPlayership 'barrelRoll)

<New tutorials, modding resources, and official extension stuff coming to this space soon!>
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

My whole code is this:

Code: Select all

<OnCreate>
				(block nil
					(setq theObject gSource)
					(setq charonStationsList (list &stCharonPirateOutpost3; &stCharonPirateOutpost2a;))
					(sysAddObjRecurringTimerEvent 1000 gSource 'Build)
					(setq CharonStationRan (random charonStationsList))
				)
			</OnCreate>
			<Build>
					(sysCreateStation CharonStationRan (sysVectorPolarOffset (objGetPosition theObject) (random 0 359) (random 50 400)))
			</Build>
It just keeps spawning a Charon Outpost (&stCharonPirateOutpost2a). &stCharonPirateOutpost3 is a stronghold by the way.
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
Prophet
Militia Captain
Militia Captain
Posts: 826
Joined: Tue Nov 18, 2008 6:09 pm

I would recommend saving CharonStationRand as a local variable rather than a global variable as multiple instances will collide and overwrite any previous values. It is probably not your issue but is a good habit to not use the global unless necessary.

Code: Select all

        <OnCreate>
           (block nil
               (sysAddObjRecurringTimerEvent 1000 gSource 'Build)
               (objSetData gSource 'CharonStationRan (random (list &stCharonPirateOutpost3; &stCharonPirateOutpost2a;)))
            )
         </OnCreate>
         <Build>
               (sysCreateStation (objGetData gSource 'CharonStationRan) (sysVectorPolarOffset (objGetPosition theObject) (random 0 359) (random 50 400)))
         </Build>
Coming soon: The Syrtian War adventure mod!
A Turret defense genre mod exploring the worst era in Earth's history.
Can you defend the Earth from the Syrtian invaders?
Stay tuned for updates!
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

How do I do that? My knowledge of scripting is very limited, mostly I know setq, lists, timers, and several functions like sysCreateStation. I really don't know how to save it locally.
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
Prophet
Militia Captain
Militia Captain
Posts: 826
Joined: Tue Nov 18, 2008 6:09 pm

The code I posted uses a local var.

Example of setting the var "foo" as a global var

Code: Select all

(block nil
(setq foo 1)
)
foo will be accessible anywhere anytime but if multiple sources are modifying it often you cannot rely on it being what you expect in some circumstances.

Example of setting the var "foo" as a temp var

Code: Select all

(block (foo)
(setq foo 1)
)
notice 'foo' in the first argument of the block, foo is only valid inside. Anywhere else foo will eval to nil.

Example of setting the var "foo" as a local var on the playership

Code: Select all

(block nil
(objSetData gPlayerShip "foo" 1)
)
This is the most reliable method for most cases. As long as the object the data is stored on is in the same system as the player, the data can be accessed.
Coming soon: The Syrtian War adventure mod!
A Turret defense genre mod exploring the worst era in Earth's history.
Can you defend the Earth from the Syrtian invaders?
Stay tuned for updates!
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

Prophet is right, if you have multiple spaceObjects running the same OnCreate with the same global variable, then I'm not surprised you see something strange. :D

In that case I would follow Prophet idea and save the data on the same spaceObject as the event.
In this way you can have multiple spaceObject, all running the same event using their own data.

Eventually, if you want to manipulate the list of stations, you can save that on the playership (or as a global variable, but I recommend the first method), so that is globally available.
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

Ok thanks for the help.
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

After fiddling around with some code to make it choose randomly, it turns out the easiest way to make it work is to do this:

Code: Select all

			<OnCreate>
				(block (charonStationsList)
					(setq theObject gSource)

					(sysAddObjRecurringTimerEvent 1000 gSource 'Build)
				)
			</OnCreate>
			<Build>
					(sysCreateStation (random (list &stCharonPirateOutpost3; &stCharonPirateOutpost2a;)) (sysVectorPolarOffset (objGetPosition theObject) (random 0 359) (random 50 400)))
			</Build>
I just had to laugh that the only way that works is the way that just chooses a random station in the list. (BTW I realized that my problem was that the game set the data in <OnCreate>, so it didn't choose a new one. Just had to laugh that this worked :lol: :lol: :lol: :lol:
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

I would reduce that to:

Code: Select all

<OnCreate>
  (block nil
    (sysAddObjRecurringTimerEvent 1000 gSource 'Build)
  )
</OnCreate>
<Build>
  (block (station)
    (setq station (random (list &stCharonPirateOutpost3; &stCharonPirateOutpost2a;)))
    (sysCreateStation station (sysVectorPolarOffset (objGetPosition gSource) (random 0 359) (random 50 400)))
</Build>
You can of course leave out the independant setting of `station`. It is just as fine to do that inline as you did in your example. The main difference is that gSource can be used everywhere. It is a global value that will always represent the object the event is running on.
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

alterecco wrote:The main difference is that gSource can be used everywhere. It is a global value that will always represent the object the event is running on.
I saw on Xelerus that it did not recognize gSource. But if it works, than I'm all for reducing lines! :D
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Drako Slyith wrote:I saw on Xelerus that it did not recognize gSource.
Where did you see that?
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

Here:
Note: unlike sysCreateShip, this function will not take the position of a spaceobject given to it. Use (objGetPosition theObject) if you need that functionality.
I took that to mean it couldn't take gSource.
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Ahh, ok

gSource is just a variable that is set by the engine. It is typically set and valid inside all game events and will contain the object that the event is running on.
Post Reply