Ship rotation mod idea.

A place to discuss mods in development and concepts for new mods.
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

Wow. Thanks, marsrocks. Excellent info here. I'm really grateful.
marsrocks wrote:I think we have to initially have our code fit into one of the pre-defined events – with oncreate being guaranteed to run.
Cool. Now I get the reasoning. Creating the ship is guaranteed to run the code. There are probably other ways but not yet known. objFireItemEvent may be useful here (already tried objFireEvent). This is why I am currently using dockscreens. Not because they are the least fiddly way of doing it, but because I know how to make them work (well, usually :lol:).
And thanks for those wiki links. Extremely helpful. I get frustrated by the wiki because often it seems to be an automatic "This topic does not exist yet" page generator.
marsrocks wrote:If we have 40 facings (360/40=9) then each facing is 9 degrees from the next. With 120 (360/120=3), then each facing is 3 degrees off the next. Also, I don’t want my next to last turn to beyond the target I want – so, if I am moving 10 degrees at a time – then that gives me another 10 degree error to account for and avoid. 10 (potential error from going too far)+9 (if 40 facings)=19. So, I felt like I needed to have a minimum number here of 19 – and 20 degrees is close enough in case I miscalculated. This also gives it a nice snap when it hits the target I want.
Of course. Now I get it. Otherwise you change the rotation value but the ship won't rotate unless it's far enough to get to the next facing. Ties in beautifully with AP's shpGetImageDesc code. But I am intrigued by the glitch you mentioned with the ship not turning in one direction at lower degree values. "The game is afoot."
marsrocks wrote:Again – no event runs until you have some pre-defined transcode allowed event run first. – so my timers are put in oncreate – and then other events I make up can run from there. The computer is looking for those predefined transcode events – but will not actively look for the ones you make up. Those new ones have to be referenced - and put in the computer’s face so to speak before they will run.
This, I think, is the critical bit of info I needed. I've got the code there but the game is ignoring it because (in an evil digital voice) 'your puny code is not worthy for some reason which we aren't going to tell you'.

I ran through all the code examples you put up before I posted the non-func mod. Same problems. Can run the code within <OnGlobalPaneInit> easily but it won't refer to or call (whichever jargon) to anything else in the <Events> block. All I was looking for was a text dbgOutput but no luck. objFireItemEvent may work here (from those links you posted, thanks again) or it may be as you say, it won't run in a virtual item. I did think at one stage that scrAddAction might be interfering but your examples above pretty much exclude this. Will probably just use your example and create a ship to run the code if something doesn't start working before I go to the next version using Invoke. Thanks for your help.

For general info, here's a couple more links from the pages marsrocks listed above with info on Events:
http://forums.kronosaur.com/viewtopic.php?f=8&t=1997
http://wiki.kronosaur.com/modding/xml/itemtype#events
http://wiki.kronosaur.com/modding/xml/designtype#events
Stupid code. Do what I want, not what I typed in!
marsrocks
Commonwealth Pilot
Commonwealth Pilot
Posts: 55
Joined: Fri Nov 05, 2010 6:29 pm

relanat,

Also look at the file digdug created on events.

(This is awesome digdug!)

http://forums.kronosaur.com/viewtopic.php?f=8&t=7324
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

Yes. digdug for King, er, Queen, umm, yes, that's it...non-gender-specific Monarch of the Universe (or N-G-SMOTU for short). Thanks, that events file is great. It's now in my modding file with all the other very useful stuff (like AE Function Help and the xelerus functionlist text dump).

To get the ship rotating I ended up using marsrocks' TargetLock code in a 'not-real' ship (many thanks, marsrocks). I couldn't make timer events run in items no matter what I tried (even in an <OnCreate> block in an item type). objFireItemEvent would run <code> blocks but the timers wouldn't kick in.

Used sysCreateShip in the block area of the scrAddAction function and then had a <ShipClass> that only had an image, no other attributes or values. Then started everything in OnCreate. Works great now.

Code: Select all

(if (eq aScreenUNID &dsShipInterior;)
	(scrAddAction
		gScreen
		'addPointOption
		4
		"Point"
		 "P"
		(block nil
		;here we create a not-real ship to give a framework for the timer events to run
		;for whatever reason timer events won't run in items code here
		(sysCreateShip &scNotRealCodeShip; nil &svPlayer;)
		;now we 'undock' from the dock screen so we can watch the ship turn
		(scrExitScreen gScreen 'forceUndock)
		)

</OnGlobalPaneInit>

</Events>
</ItemType>
	
<ShipClass UNID="&scNotRealCodeShip;"
			>
	;looks like the only thing a ship needs is an image. Game crashes without it
	<Image	imageID="&rsItems1;" imageX="0" imageY="0" imageWidth="1" imageHeight="1" imageFrameCount="0" imageTicksPerFrame="0"/>

<Events>
	<OnCreate>
		(block Nil
		;here we start with a timer event. OnCreate is a good place, apparently, for this
		;there is also a command to go to "CarDirection"
		(sysAddObjTimerEvent 2 gSource 'CarDirection)
		(sysAddObjTimerEvent (random 100 200) gSource 'Disappear)
		)
	</OnCreate>
Next is a keyboard based one using invoke (thanks for the idea, gunship256) and eventually one that will stop the ship when it hits a cardinal point.

Interestingly, gunship256 has been having trouble to get code to run in scrAddAction as well. So scrAddAction may have something to do with it. I won't abandon the idea totally without further investigation.

EDIT: xelerus is having one of its bad days so I'll attach the latest version here. Eventually all three basic pointing mods will be available there.
Second EDIT: Mods now on xelerus so I've remove the incorrect attached file
Last edited by relanat on Tue Apr 12, 2016 4:49 am, edited 1 time in total.
Stupid code. Do what I want, not what I typed in!
marsrocks
Commonwealth Pilot
Commonwealth Pilot
Posts: 55
Joined: Fri Nov 05, 2010 6:29 pm

relanat, I think you uploaded the wrong file - not working.
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

Oops. I certainly did. :oops:

Now on xelerus: Ship Pointing Mods
http://xelerus.de/index.php?s=mod&id=1522&d=1

Hopefully I got those files right! :? :lol:
Stupid code. Do what I want, not what I typed in!
Post Reply