Why won't this overlay work?

Freeform discussion about anything related to modding Transcendence.
Post Reply
phantomfoot
Anarchist
Anarchist
Posts: 18
Joined: Sun Mar 21, 2010 8:13 pm

Thu Apr 08, 2010 10:55 pm

I'm trying to do an overlay for a ship mod, but the code below doesn't seem to do anything. There are no errors, it just does nothing.

I'm trying to say "If the playership's velocity = 0 (i.e. stationary), then overlay an image on the playership"

Code: Select all

<ItemType UNID="&itAnimation;"
			virtual=			"true"
            deviceSlots=        "0">
				<Events>
					<OnUpdate> 
				
					(setq shipSpeed (objgetVel gPlayerShip))
					(if (eq (shipSpeed) 0)
						(objAddOverlay gPlayerShip &ovAnimation; (ObjGetPos gPlayership) 0) 
						)
					
						
					</OnUpdate>
			</Events>
		</ItemType>
	
	<OverlayType UNID="&ovAnimation;">
		<Effect>
			<Image imageID="&rsDummy_left_up1;" imageX="0" imageY="0" imageWidth="48" imageHeight="48" imageFrameCount="2" imageTicksPerFrame="10"/>
		</Effect>
	</OverlayType>

Still learning the ropes so apologies if it's not even in the ballpark!

Any ideas?

User avatar
Prophet
Militia Captain
Militia Captain
Posts: 826
Joined: Tue Nov 18, 2008 6:09 pm

Thu Apr 08, 2010 11:13 pm

That's a good first attempt, you're on the right track.

First, in the onUpdate event you must enclose the functions in a (block ...) and secondly objGetVel returns a velocity vector (which will never eq 0) try wrapping it in sysVectorSpeed to get an integer (% of lightspeed).

try this:

Code: Select all

(block (shipspeed)
 (setq shipspeed (sysVectorSpeed (objgetVel gPlayerShip)))
 (if (eq shipspeed 0)
   (objAddOverlay gPlayerShip &ovAnimation; (objgetPos gPlayerShip) 0)
 )
)
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!

phantomfoot
Anarchist
Anarchist
Posts: 18
Joined: Sun Mar 21, 2010 8:13 pm

Fri Apr 09, 2010 6:19 pm

Great! Thanks, I forgot about the sysVectorSpeed.

Ok so now the overlay is appearing, but it stays on even if velocity is greater than 0. Once it appears, it remains there for good.

Is there any way to remove it once the playership velocity > 0?

I tried this:

Code: Select all

(if (gr shipspeed 1)
  (objRemoveOverlay gPlayerShip OverlayID) 
   )
but it didn't work. What is the OverlayID and how do I get it?

User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

Fri Apr 09, 2010 6:30 pm

objAddOverlay returns the id of the added overlay so save that and use that to remove.
Crying is not a proper retort!

User avatar
Bobby
Militia Captain
Militia Captain
Posts: 675
Joined: Wed Jul 25, 2007 7:39 pm

Fri Apr 09, 2010 6:43 pm

or you could set the overlay to expire after 30 ticks, if it isn't put back next time the event runs it will go away. A long animation will probably be cut off and restarted every second though.

Example:

Code: Select all

					(objAddOverlay 
						gSource
						overlay 
						(sysVectorPolarOffset gSource direction distance)
						0
						28
					)
from my Agauptera mod, the "28" is the number of ticks it will last.

phantomfoot
Anarchist
Anarchist
Posts: 18
Joined: Sun Mar 21, 2010 8:13 pm

Sat Apr 10, 2010 10:54 am

Betelgeuse wrote:objAddOverlay returns the id of the added overlay so save that and use that to remove.
That sounds like what I want. Could you possibly give an example of how I would save it?

Would I use objGetOverlayData, or objSetoverlayData, or something else?

Sorry to ask, only i was trying all last night and couldn't get it to work.

*Blush* :oops:

User avatar
Prophet
Militia Captain
Militia Captain
Posts: 826
Joined: Tue Nov 18, 2008 6:09 pm

Sat Apr 10, 2010 1:03 pm

When you apply the overlay, use:

Code: Select all

(objSetData gSource "overlayID" (objAddOverlay gSource overlay (sysVectorPolarOffset gSource direction distance)  0  28 ))
Which will save the overlay ID on the object. When you want to remove the overlay use:

Code: Select all

(objRemoveOverlay gSource (objGetData gSource "overlayID"))
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!

phantomfoot
Anarchist
Anarchist
Posts: 18
Joined: Sun Mar 21, 2010 8:13 pm

Sat Apr 10, 2010 3:12 pm

Nice one! Thanks, that kinda makes sense now.

Almost there. But something strange is happening. Sometimes it works (the overlay adds and removes itself fine), sometimes the overlay stays there (it doesn't get removed), and sometimes it doesn't work at all (the overlay doesn't even get added).

How can that be?

Here's my latest code:

Code: Select all

<OnUpdate> 
			
(block (shipspeed)
 (setq shipspeed (sysVectorSpeed (objgetVel gPlayerShip)))

 (if (gr shipspeed 0)
 (objSetData gPlayerShip "anim" (objAddOverlay gPlayerShip &ovAnimation; (objgetPos gPlayerShip) 0))
 )

 (if (eq shipspeed 0)
  (objRemoveOverlay gSource (objGetData gPlayerShip "anim")) 
   )
)
</OnUpdate>
(p.s. I've changed it around so that the overlay is added when the ships velocity is >0, and removed when stationary, or at least that is what I'm trying to do :P)

Jeoshua
Militia Lieutenant
Militia Lieutenant
Posts: 163
Joined: Sat Sep 06, 2008 3:48 pm

Sat Apr 10, 2010 3:59 pm

check that objAddOverlay once again... it looks like you didn't give it a timeout.

User avatar
Bobby
Militia Captain
Militia Captain
Posts: 675
Joined: Wed Jul 25, 2007 7:39 pm

Sat Apr 10, 2010 7:19 pm

It looks like your mod will continue to add or remove overlays every one second regardless if it is already there or not. if you move for two seconds the first overlay's id could be overwritten by the second and might not be removed, assuming an overlay's id points to a specific overlay not all of that type.

This should add an overlay once on moving, and remove it once on stopping.

Code: Select all

(block (shipspeed)
 (setq shipspeed (sysVectorSpeed (objgetVel gPlayerShip)))

 (switch
  (and (eq shipspeed 0) ((objGetData gPlayerShip "anim")))
   (block Nil
    (objRemoveOverlay gSource (objGetData gPlayerShip "anim"))
    (objSetData gPlayerShip "anim" Nil)
   )
  
  (and (gr shipspeed 0) (not (objGetData gPlayerShip "anim")))
   (objSetData gPlayerShip "anim" (objAddOverlay gPlayerShip &ovAnimation; (objgetPos gPlayerShip) 0))
 )
)
I haven't tested it and foresee potential trouble with undefined variables errors, but nothing an (isError) can't solve.

phantomfoot
Anarchist
Anarchist
Posts: 18
Joined: Sun Mar 21, 2010 8:13 pm

Sun Apr 11, 2010 12:04 pm

Jeoshua wrote:check that objAddOverlay once again... it looks like you didn't give it a timeout.
I don't think the timeout thing is what I'm looking for. I tried it, but because it keeps removing itself every 28 ticks (or however long you set it), the overlay blinks on and off.

I am hoping the overlay will be continuous as long as the ship is moving.

User avatar
Prophet
Militia Captain
Militia Captain
Posts: 826
Joined: Tue Nov 18, 2008 6:09 pm

Sun Apr 11, 2010 12:49 pm

You almost had it perfect! :D
The last piece that you need is to check that the ship doesn't already have the overlay when you want to add it.

Code: Select all

<OnUpdate> 
          
(block (shipspeed) 
 (setq shipspeed (sysVectorSpeed (objgetVel gPlayerShip))) 

 (if (and (gr shipspeed 0) (eq (objGetData gPlayerShip "anim") nil))
 (objSetData gPlayerShip "anim" (objAddOverlay gPlayerShip &ovAnimation; (objgetPos gPlayerShip) 0)) 
 ) 

 (if (eq shipspeed 0)
 (block Nil
  (objSetData gPlayerShip "anim" Nil)
  (objRemoveOverlay gSource (objGetData gPlayerShip "anim")) 
  )
   ) 
) 
</OnUpdate> 
If you come to the IRC channel someone can work with you and get this going really fast. it's ##transcendence on freenode.
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!

phantomfoot
Anarchist
Anarchist
Posts: 18
Joined: Sun Mar 21, 2010 8:13 pm

Sun Apr 11, 2010 1:52 pm

Eureka! I got it to work! This seems to work just fine:

Code: Select all

	(block (shipspeed)
 (setq shipspeed (sysVectorSpeed (objgetVel gPlayerShip)))
 (objRemoveOverlay gSource (objGetData gPlayerShip "anim"))

 (if (gr shipspeed 0)
 (objSetData gPlayerShip "anim" (objAddOverlay gPlayerShip &ovAnimationStill; (objgetPos gPlayerShip) 0))
 )

 (if (eq shipspeed 0)
  (objRemoveOverlay gSource (objGetData gPlayerShip "anim"))
   )
) 
I just added an extra objRemoveOverlay outside of the if statements, and the overlay now turns on and off perfectly, depending on the ship's speed.

There is a small delay between when the ship starts to move and when the overlay appears (and also when it is removed), but I don't know if that can be helped?

Hmm for some reason Prophet your code didn't seem to work - it still didn't remove the overlay. But I am happy with the above for now :) Thanks everyone for all your help! Truly wonderful forum! :)

User avatar
Bobby
Militia Captain
Militia Captain
Posts: 675
Joined: Wed Jul 25, 2007 7:39 pm

Sun Apr 11, 2010 2:40 pm

OnUpdate works once per second, or every 30 ticks. If your code were on an event that ran more frequently, like 5 ticks, the delay would be less.

phantomfoot
Anarchist
Anarchist
Posts: 18
Joined: Sun Mar 21, 2010 8:13 pm

Mon Apr 12, 2010 9:53 am

Ah yes, I can see how that is done. Thanks for the tip.

Post Reply