Hi all,
I just added to my Adventure Mod 2 insystem freighters, incapable of hyperjump. So now I would want, on system creation, to randomly generate a number of freighters that will fly around the system.
I've already done this with a single ship class. Now I would like to do 2 things :
1/ Both classes share the same behavior code, I would like to have this code written once,
2/ I would like to have a generic probability table somewhere and a generic function that will use it to generate random freighters. This table will have to be only once in the entire Adventure, so that when I'll add more classes I'll only have to edit it once.
Coding (1) and the function part of (2) is easy. It implies lambdas, globals and so on... But where to put the table itself ? I've seen nowhere an example of a universe-wide table. They are all linked to ship, station of item classes...
Before crashing the game n and n times by trying at random, I would like to better know where to head ^-^ If someone has an answer, even a hint, many thanks in advance !
How to implement a shared table ?
- Periculi
- Fleet Officer
- Posts: 1282
- Joined: Sat Oct 13, 2007 7:48 pm
- Location: Necroposting in a forum near you
<Globals> would be the likely candidate there- place your tables and functions in the global element and they can be used by anything. Look at how the game globals for commerce and trading are being done.
You can also store a static table in any station and just reference it from code as needed- it doesn't need to be in the object that is using the code, look at how Domina is set up for more ideas on using the static data in a unused station element.
You can also store a static table in any station and just reference it from code as needed- it doesn't need to be in the object that is using the code, look at how Domina is set up for more ideas on using the static data in a unused station element.
- Mutos
- Militia Lieutenant
- Posts: 218
- Joined: Thu Aug 14, 2008 3:31 am
- Location: Near Paris, France
- Contact:
Hi all,
For now I didn't succeed, but I also think I didn't try hard enough ! So I concentrated on another task, to get back to that later. Now I got freighters flying past my systems and that works... Time to settle the globals issue now !
To be more specific, Periculi, the problem with Globals is not how to store the data in the XML, that's a breeze. But I still don't know how to retrieve them in an <OnGlobalSystemCreated> event. All I see is objGetGlobalData and objSetGlobalData, which ned an object. When I pass a system, it wouldn't do anything. I may try passing the gPlayerShip object, just thought of that..
For now I didn't succeed, but I also think I didn't try hard enough ! So I concentrated on another task, to get back to that later. Now I got freighters flying past my systems and that works... Time to settle the globals issue now !
To be more specific, Periculi, the problem with Globals is not how to store the data in the XML, that's a breeze. But I still don't know how to retrieve them in an <OnGlobalSystemCreated> event. All I see is objGetGlobalData and objSetGlobalData, which ned an object. When I pass a system, it wouldn't do anything. I may try passing the gPlayerShip object, just thought of that..
- Periculi
- Fleet Officer
- Posts: 1282
- Joined: Sat Oct 13, 2007 7:48 pm
- Location: Necroposting in a forum near you
You have a great many options actually.
sysGetData, sysSetData for systems
objGetData, objSetData - which actually is limited, use the below typ functions instead:
typGetGlobalData, typSetGlobalData
typGetStaticData, typSetStaticData
You could also just store your table as a function:
(setq exampleTable (lambda nil
(block (sample)
(setq sample
(list
(list A B C)
(list D E F)
)
)
)
))
Then from any other piece of code simply do (setq getTable (exampleTable)) which would then return the list of lists in the function. I have no idea what you are calling a table, so you may need to set things up differently.
I have found that there are a great many ways to set and get data in many variations for the game, and am thinking that perhaps you just need to explore further how to use the various getter and setter functions. Try Xelerus references for a start.
sysGetData, sysSetData for systems
objGetData, objSetData - which actually is limited, use the below typ functions instead:
typGetGlobalData, typSetGlobalData
typGetStaticData, typSetStaticData
You could also just store your table as a function:
(setq exampleTable (lambda nil
(block (sample)
(setq sample
(list
(list A B C)
(list D E F)
)
)
)
))
Then from any other piece of code simply do (setq getTable (exampleTable)) which would then return the list of lists in the function. I have no idea what you are calling a table, so you may need to set things up differently.
I have found that there are a great many ways to set and get data in many variations for the game, and am thinking that perhaps you just need to explore further how to use the various getter and setter functions. Try Xelerus references for a start.
- Mutos
- Militia Lieutenant
- Posts: 218
- Joined: Thu Aug 14, 2008 3:31 am
- Location: Near Paris, France
- Contact:
Hi Periculi,
The point seems to be that I'm a little lost in all these ways... I read Xelerus descriptions, compared with some code in the source and your explanations,. Now I begin to understand some facts, but there are still many dark spots.
For instance... Where is stored each of the data pieces you retrieve with all these functions, what are the differences between storing in Globals or StaticData, can Static go inside of Globals, can XML-set globals and/or statics be modified, on which type of objects do they apply, how to use each and in which case it is possible or not, appropriate or not. ? That sort of questions. Some are easy, and on some even I've got answers, but I still hasn't got the big picture.
So I'll check and test further, I believe understanding will come over time, piece after piece. And I'll try to sum it up in a forum post for others to use, maybe edit the first post of this thread...
The point seems to be that I'm a little lost in all these ways... I read Xelerus descriptions, compared with some code in the source and your explanations,. Now I begin to understand some facts, but there are still many dark spots.
For instance... Where is stored each of the data pieces you retrieve with all these functions, what are the differences between storing in Globals or StaticData, can Static go inside of Globals, can XML-set globals and/or statics be modified, on which type of objects do they apply, how to use each and in which case it is possible or not, appropriate or not. ? That sort of questions. Some are easy, and on some even I've got answers, but I still hasn't got the big picture.
So I'll check and test further, I believe understanding will come over time, piece after piece. And I'll try to sum it up in a forum post for others to use, maybe edit the first post of this thread...