Trying to use sysGetLevel function: What am I doing wrong?

Freeform discussion about anything related to modding Transcendence.
Post Reply
Yama
Militia Lieutenant
Militia Lieutenant
Posts: 114
Joined: Mon Feb 07, 2011 1:32 am
Location: in the apprenticeship program at a Tinker station....

I'm trying make Tinker stations that stock higher level inventory (damaged items for sale), when the stations are spawned in higher-level systems.

I thought I could use the sysGetLevel function to control this but haven't figured out how to make it work. The condition I've tried to setup for the "switch" function gets ignored and all the higher level items are being stocked, even in low level systems. I've also tried coding this using the "if" function instead and had the same problem.

Please take a look at my code and tell me what I'm doing wrong.

Code: Select all

<Items>	 
		;; All Tinker stations should get these items
		<RandomItem count="3d6" 
			criteria=      "aswd -Illegal; -Military; -NotForSale;"
			level=         "3"
			levelCurve=      "2"
			damaged=      "100"
		/>
		(Block (syslevel)
			(setq syslevel (sysGetLevel))
			;; Only tinker stations spawned in level 4 and higher systems should get these items
			(switch	(gr syslevel 3)				
				(Block Nil
					<RandomItem count="2d6"
						criteria=		"aswd -NotForSale;"
						level=			"5"
						levelCurve=		"2"
						damaged=		"100"
								/>
					<RandomItem count="3d6"
						criteria=		"aswd -NotForSale;"
						level=			"7"
						levelCurve=		"2"
						damaged=		"100"
								/>
					<RandomItem count="1d4+2"
						criteria=		"aswd +Military; -NotForSale;"
						level=			"7"
						levelCurve=		"2"
						damaged=		"100"
								/>
					<RandomItem count="1d4+2"
						criteria=		"aswd +Specialty; -NotForSale;"
						level=			"7"
						levelCurve=		"2"
						damaged=		"100"
								/>
				)
			)		
		)			
	</Items>
"A good ship should not look like a plumber's nightmare."
- Atarlost
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:

You can't fuse script and xml. Try this

Code: Select all

<Events>
<OnCreate>
        (block (sysLevel)
                (setq sysLevel (sysGetLevel))
                     (itmEnumTypes "*" currentItem
                           (if (gr (objGetLevel currentItem) sysLevel)
                                  (objAddItem gSource currentItem)
                           )
                     )
          )
</OnCreate>
</Events>
That code will add all items in the game of greater level than the system. If you want, say 10-20 items, then use this code:
<OnCreate>
(block (sysLevel itemList)
(setq sysLevel (sysGetLevel))
(itmEnumTypes "*" currentItem
(if (gr (objGetLevel currentItem) sysLevel)
(lnkAppend itemList currentItem)
)
)
(for i 1 (random 10 20) (objAddItem gSource (random itemList)))
)
</OnCreate>
</Events>[/code]
I haven't tested this, but it should work. Personally, I would use the second one, because it lets you choose how many items are added.
If you want only one type of items, such as weapons, replace the star with the item criteria here.
If you have any questions, feel free to ask me.
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?
Yama
Militia Lieutenant
Militia Lieutenant
Posts: 114
Joined: Mon Feb 07, 2011 1:32 am
Location: in the apprenticeship program at a Tinker station....

Hi Drako,

Sorry for not responding sooner.

For the last few hours I've been bouncing back and forth between the modding tutorials, the wiki pages and staring at the code you sent me, trying to learn enough to understand it. :? I'm still only part way there, but hopefully have reached the point that I can at least ask semi-intelligent questions.

Drako Slyith wrote:You can't fuse script and xml........
OK. I guess that these parts are the script...

Code: Select all

<Items>   
      ;; All Tinker stations should get these items
      <RandomItem count="3d6"
         criteria=      "aswd -Illegal; -Military; -NotForSale;"
         level=         "3"
         levelCurve=      "2"
         damaged=      "100"
      />     
               <RandomItem count="2d6"
                  criteria=      "aswd -NotForSale;"
                  level=         "5"
                  levelCurve=      "2"
                  damaged=      "100"
                        />
               <RandomItem count="3d6"
                  criteria=      "aswd -NotForSale;"
                  level=         "7"
                  levelCurve=      "2"
                  damaged=      "100"
                        />
               <RandomItem count="1d4+2"
                  criteria=      "aswd +Military; -NotForSale;"
                  level=         "7"
                  levelCurve=      "2"
                  damaged=      "100"
                        />
               <RandomItem count="1d4+2"
                  criteria=      "aswd +Specialty; -NotForSale;"
                  level=         "7"
                  levelCurve=      "2"
                  damaged=      "100"
                        />       
   </Items>
.... and these parts.....

Code: Select all

      (Block (syslevel)
         (setq syslevel (sysGetLevel))
         ;; Only tinker stations spawned in level 4 and higher systems should get these items
         (switch   (gr syslevel 3)            
            (Block Nil
            )
         )      
      )  
.... and the code you sent me are xml.

If that's so, it's much easier for me to read and manipulate Transcendence script than xml. Do you think there may be a way to do the trick in all script, rather than all xml? I still don't more than half comprehend what you sent me, and couldn't begin to modify it.
"A good ship should not look like a plumber's nightmare."
- Atarlost
RPC
Fleet Admiral
Fleet Admiral
Posts: 2876
Joined: Thu Feb 03, 2011 5:21 am
Location: Hmm... I'm confused. Anybody have a starmap to the Core?

Yama: read all the comments after the semicolon. Placing this in Notepad ++ makes it easier to read though.
Resources:
The Functions page on Xelerus
NOTE: Xelerus isn't updated completely. Check StarWeaver's list for the current list of functions.
StarWeaver's list of functions
The Events page on the Wiki

Code: Select all

;Events is a built-in tag that monitors events. When you put a tag such as <OnCreate> you can create events and even to refer to them using functions such as objFireEvent
<Events>
;<OnCreate> is a vanilla tag that is invoked upon an onbject's creation
<OnCreate>
		;I'll list the functions used and the Xelerus page with all the functions. Just find the function and ask if you have any more questions [or go to IRC if you have some function questions, responses are faster there]
			;block
			;setq
			;sysGetLevel
			;itmEnumTypes
			;if
			;gr
			;objGetLevel
			;objAddItem
			;for
		;here block is used to have a series of code executed as a block. Otherwise, only the first line would be executed or you will get a debug notification such as ##spaceObjectitcamefrom <OnCreate> tag##: too many arguements etc etc...
        (block
			; here Drako defines his local variables in the block [if they are not declared than they will globally defined]
			(sysLevel)			
				;he defines sysLevel in code
                (setq sysLevel (sysGetLevel))
					;I have no clue how to use ItmEnumTypes... a look at the Xelerus page may help though...
                     (itmEnumTypes "*" currentItem
							;if is a conditional function that is invoked only when the conditional is non-Nil [aka it is something other than undefined, or explicitly defined to be Nil]							
                           (if
								;gr is a greater than function. In the Xelerus page, it evaluates two variables and then says if they are greater or not. If not, it returns Nil.
									;NOTE: the gr function is the conditional for the "if" function [quotations on if to exemplify its use as a name of a function] Since gr than returns a value of nil or non-Nil, it is useful for the "if" function. 
								(gr (objGetLevel currentItem) sysLevel)
									;objAddItem adds an item to a spaceobject. In this case, it is gSource, which is a 'populated variable' [I have no clue what that means] in <OnCreate>. A list of populated variables and vanilla tags can be seen on the wiki: http://wiki.neurohack.com/transcendence/wiki/events?s
                                  (objAddItem gSource currentItem)
							;end parentheses-- It is important to keep track of your parentheses! Sometimes it is hard to take note of but one missing parentheses will ruin the whole segment of code!
                           )
                     )
          )
</OnCreate>
</Events>

;again the <Events> tag...
<Events>
;and <OnCreate>...
<OnCreate>
	;as well as block...
	(block
		;more local variables to be defined in the block...
		(sysLevel itemList)
		;there Drako defines sysLevel...
		(setq sysLevel (sysGetLevel))
		;I don't know how to use itmEnumTypes...
		(itmEnumTypes "*" currentItem
		;the if function...
		(if 
			;gr function [and the conditional for "if" BTW]...
			(gr (objGetLevel currentItem) sysLevel)
			;No idea what lnkAppend does... [I haven't used it yet]
			(lnkAppend itemList currentItem)
			)
		)
		;"For" is another function that is used to repeat segments of code
		(for i 1 (random 10 20) (objAddItem gSource (random itemList)))
		;end parentheses
		)
</OnCreate>
</Events>
; Good luck! [and I hope this was helpful to you! I'm sorry that I couldn't explain all the functions.]
Tutorial List on the Wiki and Installing Mods
Get on Discord for mod help and general chat
Image
Image
Der Tod ist der zeitlose Frieden und das leben ist der Krieg
Wir müssen wissen — wir werden wissen!
I don't want any sort of copyright on my Transcendence mods. Feel free to take/modify whatever you want.
Yama
Militia Lieutenant
Militia Lieutenant
Posts: 114
Joined: Mon Feb 07, 2011 1:32 am
Location: in the apprenticeship program at a Tinker station....

Thanks RPC for commenting Drako's code. :) I'm already using Notepad++ and it has been a big help.

I believe I've found a way that I can continue using script to create the items and still be able to limit the level and type of the items created, according to the level of the system the station is spawned in. I'm afraid it's not very elegant, but am pretty sure it can be made to work. It'll likely take another day to work out the details and test it. I'll post the code here as soon as I'm done. It'll be easier to show than explain.
"A good ship should not look like a plumber's nightmare."
- Atarlost
george moromisato
Developer
Developer
Posts: 2998
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

XML is declarative: You describe (declare) what you want and the game does it.
TransLISP is procedural: You tell the game what to do step by step.

Declarative programming is easier, but less flexible.
Procedural programming is harder, but more capable.

In Transcendence you can sometimes accomplish the same goal both declaratively (via XML) and procedurally (via TransLISP). Which you use is up to you.

In this case, I think there is also a declarative way to do what you want:

Code: Select all

<Items>    
      <!-- All Tinker stations should get these items -->
      <RandomItem count="3d6" 
         criteria=      "aswd -Illegal; -Military; -NotForSale;"
         level=         "3"
         levelCurve=      "2"
         damaged=      "100"
      />

      <LevelTable>
          <!-- The levelFrequency syntax specifies the frequency of something at each level. Every character represents a level,
                 starting with 1 (and with a space every 5 levels). The first three characters (---) represent the first three level
                 '-' means "not encountered at this level". The rest of the characters (cc ccccc) represent levels 4-10. 'c' means
                 "commonly encountered".

                 When items are generated, we loop through all the elements of <LevelTable> and calculate a chance of being
                 encountered for element. The chance is based on system level, so at levels 1-3, the probability for the <Group>
                 is 0%. At levels 4-10, the probability for the group is 100% (since the <Group> is the only element).
          -->

          <Group levelFrequency="---cc ccccc">
               <RandomItem count="2d6"
                  criteria=      "aswd -NotForSale;"
                  level=         "5"
                  levelCurve=      "2"
                  damaged=      "100"
                        />
               <RandomItem count="3d6"
                  criteria=      "aswd -NotForSale;"
                  level=         "7"
                  levelCurve=      "2"
                  damaged=      "100"
                        />
               <RandomItem count="1d4+2"
                  criteria=      "aswd +Military; -NotForSale;"
                  level=         "7"
                  levelCurve=      "2"
                  damaged=      "100"
                        />
               <RandomItem count="1d4+2"
                  criteria=      "aswd +Specialty; -NotForSale;"
                  level=         "7"
                  levelCurve=      "2"
                  damaged=      "100"
                        />
         </Group>
      </LevelTable>
   </Items>
Note: I haven't tried the above, so don't know if I got it 100% right.
Yama
Militia Lieutenant
Militia Lieutenant
Posts: 114
Joined: Mon Feb 07, 2011 1:32 am
Location: in the apprenticeship program at a Tinker station....

george moromisato wrote:XML is declarative: You describe (declare) what you want and the game does it.
TransLISP is procedural: You tell the game what to do step by step.

Declarative programming is easier, but less flexible.
Procedural programming is harder, but more capable.

In Transcendence you can sometimes accomplish the same goal both declaratively (via XML) and procedurally (via TransLISP). Which you use is up to you.

In this case, I think there is also a declarative way to do what you want:
I think I've got it now.

It's clear that I'd guessed wrong (backwards) as to which parts are script and which are xml. :oops: I really do prefer working in xml where possible.
george moromisato wrote:

Code: Select all

<Items>    
      <!-- All Tinker stations should get these items -->
      <RandomItem count="3d6" 
         criteria=      "aswd -Illegal; -Military; -NotForSale;"
         level=         "3"
         levelCurve=      "2"
         damaged=      "100"
      />

      <LevelTable>
          <!-- The levelFrequency syntax specifies the frequency of something at each level. Every character represents a level,
                 starting with 1 (and with a space every 5 levels). The first three characters (---) represent the first three level
                 '-' means "not encountered at this level". The rest of the characters (cc ccccc) represent levels 4-10. 'c' means
                 "commonly encountered".

                 When items are generated, we loop through all the elements of <LevelTable> and calculate a chance of being
                 encountered for element. The chance is based on system level, so at levels 1-3, the probability for the <Group>
                 is 0%. At levels 4-10, the probability for the group is 100% (since the <Group> is the only element).
          -->

          <Group levelFrequency="---cc ccccc">
               <RandomItem count="2d6"
                  criteria=      "aswd -NotForSale;"
                  level=         "5"
                  levelCurve=      "2"
                  damaged=      "100"
                        />
               <RandomItem count="3d6"
                  criteria=      "aswd -NotForSale;"
                  level=         "7"
                  levelCurve=      "2"
                  damaged=      "100"
                        />
               <RandomItem count="1d4+2"
                  criteria=      "aswd +Military; -NotForSale;"
                  level=         "7"
                  levelCurve=      "2"
                  damaged=      "100"
                        />
               <RandomItem count="1d4+2"
                  criteria=      "aswd +Specialty; -NotForSale;"
                  level=         "7"
                  levelCurve=      "2"
                  damaged=      "100"
                        />
         </Group>
      </LevelTable>
   </Items>
Note: I haven't tried the above, so don't know if I got it 100% right.
I'll give it a try. :D That appears to be a far cleaner and more flexible than what I was working on.

Many thanks George!!
"A good ship should not look like a plumber's nightmare."
- Atarlost
Post Reply