Timer Error (systicks)

Bug reports for the different beta versions of transcendence.
Post Reply
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

(objsetitemData gsource gitem "SFT_ticks" (systicks)) always stores nil.
Literally is the new Figuratively
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Atarlost wrote:(objsetitemData gsource gitem "SFT_ticks" (systicks)) always stores nil.
This can happen (unfortunately) if the item cannot be found on the object. In API 18 I've added an error message in this case instead of returning Nil.
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

george moromisato wrote:
Atarlost wrote:(objsetitemData gsource gitem "SFT_ticks" (systicks)) always stores nil.
This can happen (unfortunately) if the item cannot be found on the object. In API 18 I've added an error message in this case instead of returning Nil.
This is more specific.

Code: Select all

(setq AU_spinupFireTest (lambda (initialFireRateAdj finalFireRate)
	(block (fireDelayCounter fireRateCounter doNotFire spinUpCounter oldTicks)
		(setq fireDelayCounter (itmGetData gItem "FireDelayCounter"))
		(setq fireRateCounter (itmGetData gItem "FireRateCounter"))
		(setq spinUpCounter (itmGetData gItem "SpinUpCounter"))
		(setq oldTicks (itmGetData gItem "SFT_ticks"))
(dbglog oldticks " | " (systicks) " || " firedelaycounter " | " fireratecounter " | " spinupcounter)

...
		(objsetitemData gsource gItem "FireDelayCounter" fireDelayCounter)
		(objsetitemData gsource gItem "FireRateCounter" fireRateCounter)
		(objsetitemData gsource gitem "SpinUpCounter" spinUpCounter)
		(objsetitemData gsource gitem "SFT_ticks" (systicks))
...

	)
))
Gives me output like

Code: Select all

10/15/2013 20:59:45	Nil | 212976468 || Nil | Nil | Nil
10/15/2013 20:59:45	Nil | 212976500 || Nil | 8 | Nil
10/15/2013 20:59:45	Nil | 212976546 || 1 | 8 | Nil
10/15/2013 20:59:46	Nil | 212976625 || 1 | 8 | 1
10/15/2013 20:59:46	Nil | 212976656 || 1 | 8 | 2
10/15/2013 20:59:46	Nil | 212976703 || 1 | 8 | 3
10/15/2013 20:59:46	Nil | 212976765 || 1 | 8 | 4
10/15/2013 20:59:46	Nil | 212976843 || 1 | 8 | 5
10/15/2013 20:59:46	Nil | 212976875 || 1 | 8 | 6
10/15/2013 20:59:46	Nil | 212976921 || 1 | 8 | 7
10/15/2013 20:59:46	Nil | 212976984 || 1 | 8 | 8
10/15/2013 20:59:46	Nil | 212977046 || 1 | 8 | 9
10/15/2013 20:59:46	Nil | 212977109 || 1 | 7 | 9
10/15/2013 20:59:46	Nil | 212977171 || 1 | 8 | 9
10/15/2013 20:59:46	Nil | 212977250 || 1 | 7 | 9
10/15/2013 20:59:46	Nil | 212977312 || 1 | 8 | 9
10/15/2013 20:59:46	Nil | 212977375 || 1 | 7 | 9
10/15/2013 20:59:46	Nil | 212977406 || 1 | 8 | 9
10/15/2013 20:59:46	Nil | 212977468 || 1 | 7 | 9
in debug.log. SFT_ticks never stops being nil while other stuff stored on the same item in the same event works.
Literally is the new Figuratively
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Atarlost wrote:This is more specific....
This is due to a poor design on my part. Items get modified whenever you set data on them, so the item itself changes. Try this:

Code: Select all

...
(setq gItem (objsetitemData gsource gItem "FireDelayCounter" fireDelayCounter))
(setq gItem (objsetitemData gsource gItem "FireRateCounter" fireRateCounter))
(setq gItem (objsetitemData gsource gitem "SpinUpCounter" spinUpCounter))
(setq gItem (objsetitemData gsource gitem "SFT_ticks" (systicks)))
...
A call like (objSetItemData gSource gItem ...) modifies the item itself, but the value of gItem does not change automatically. So on subsequent calls the original gItem can no longer be found on the object (because it has been modified).

[This is all due to the fact that internally multiple items are folded together (i.e., if you have two laser cannons there is only a single item data structure with a count of 2). Because of that there is no unique ID for an item, so you always have to refer to items by value. But setting data on an item changes the value.]
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

Wouldn't that cause fireDelayCounter and spinUpCounter to also always be nil if that were the cause?

edit: seems to fix, but this is still inconsistent behavior as far as I can tell.
Literally is the new Figuratively
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Atarlost wrote:Wouldn't that cause fireDelayCounter and spinUpCounter to also always be nil if that were the cause?
It depends on the state of gItem at the time that objsetitemData is called. Think about it this way: There are TWO item structures that you need to worry about. One is on the ship itself (which you are trying to change). The other is stored in gItem and starts out being equal in value to the ship item.

When you call objSetItemData, it changes the ship's item structure and returns the new value of the item. Unless you set gItem to the new value, the two values diverge. If the values don't match, the next time you try to call a function with gItem, that value will not be found on the ship, so we don't know which item to modify.

If you make a call to objSetItemData that does not change the item structure (for example, if the data value you're trying to set is already set to that value) then nothing changes and gItem stays in sync. So a subsequent call to objSetItemData works properly (but if THAT call changes something then other calls will fail).

Sometimes the call to set "FireDelayCounter" did not change the value. In those cases, the next call to set "FireRateCounter" worked fine. However, something always changed in the item before it got to "SFT_ticks" so that was never getting set. You can also try setting "SFT_ticks" at the beginning. Then all other calls will fail because SFT_ticks is never the same value twice.

I've added errors in the next version that will hopefully alert people of this problem earlier.

p.s.: One last thing: You might want unvGetTick instead of systicks. unvGetTick returns the game-tick number (which is incremented every frame or 1/30th per second). systicks is the computer's tick count, which is incremented once per millisecond. [systicks is probably not useful and I should just remove it or something.]
User avatar
Aury
Fleet Admiral
Fleet Admiral
Posts: 5421
Joined: Tue Feb 05, 2008 1:10 am
Location: Somewhere in the Frontier on a Hycrotan station, working on new ships.

systicks is probably useful only for things that need to run with regards to realtime (playertime) instead of ingame time (possibly like something related to UI, not sure)
(shpOrder gPlayership 'barrelRoll)
(plySetGenome gPlayer (list 'Varalyn 'nonBinary))
Homelab Servers: Xeon Silver 4110, 16GB | Via Quadcore C4650, 16GB | Athlon 200GE, 8GB | i7 7800X, 32GB | Threadripper 1950X, 32GB | Atom x5 8350, 4GB | Opteron 8174, 16GB | Xeon E5 2620 v3, 8GB | 2x Xeon Silver 4116, 96GB, 2x 1080ti | i7 8700, 32GB, 6500XT
Workstations & Render machines: Threadripper 3990X, 128GB, 6900XT | Threadripper 2990WX, 32GB, 1080ti | Xeon Platinum 8173M, 48GB, 1070ti | R9 3900X, 16GB, Vega64 | 2x E5 2430L v2, 24GB, 970 | R7 3700X, 32GB, A6000
Gaming Systems: R9 5950X, 32GB, 6700XT
Office Systems: Xeon 5318Y, 256GB, A4000
Misc Systems: R5 3500U, 20GB | R5 2400G, 16GB | i5 7640X, 16GB, Vega56 | E5 2620, 8GB, R5 260 | P4 1.8ghz, 0.75GB, Voodoo 5 5500 | Athlon 64 x2 4400+, 1.5GB, FX 5800 Ultra | Pentium D 3.2ghz, 4GB, 7600gt | Celeron g460, 8GB, 730gt | 2x Athlon FX 74, 8GB, 8800gts 512 | FX 9590, 16GB, R9 295x2 | E350, 8GB | Phenom X4 2.6ghz, 16GB, 8800gt | random core2 duo/atom/i5/i7 laptops
Post Reply