Page 1 of 1

RotaryRead(<variable>, <variable>, ...)

Posted: Mon Apr 19, 2010 9:17 pm
by Deth good
A more compact and more functional Read...Data in one statement.

Example:
Repeat
Debug RotaryRead(348, 24, 25, 1024)
Forever

Outputs:
348
24
25
1024
348
...

Re: RotaryRead(<variable>, <variable>, ...)

Posted: Mon Apr 19, 2010 9:19 pm
by Kaeru Gaman
:?: what should this help for?

Re: RotaryRead(<variable>, <variable>, ...)

Posted: Mon Apr 19, 2010 9:27 pm
by Deth good
In my case (I code retro games) It would certainly make my code more more compact and more readable.

Re: RotaryRead(<variable>, <variable>, ...)

Posted: Mon Apr 19, 2010 9:32 pm
by Kaeru Gaman
but it is nothing you could not easily put into a selfcoded function...

and I wonder what should it be good for, really.
Oldskool Games are my passion and profession, and I don't see the real use at first glance.

Re: RotaryRead(<variable>, <variable>, ...)

Posted: Mon Apr 19, 2010 9:51 pm
by Deth good
Tried to code it in a macro and in a function but it didn't work out. (I'm not a pro coder though). You could use it for example to do animations or to do little sequences or movements in games with less code.

Re: RotaryRead(<variable>, <variable>, ...)

Posted: Mon Apr 19, 2010 9:57 pm
by Kaeru Gaman
for such things you would use an Array...

Code: Select all

#LastFrame = 3

Define n.l

Dim Phase.l(#LastFrame)

Restore PhaseTable
For n=0 To #LastFrame
  Read.l Phase(n)
Next

Define counter.l = 0
Define GlobalCounter.l = 0

Repeat
  Debug Phase(counter)
  counter +1
  If counter > #LastFrame
    counter = 0
  EndIf
  GlobalCounter +1
Until GlobalCounter > 23

End

DataSection
PhaseTable:
Data.l 348, 24, 25, 1024
EndDataSection

Re: RotaryRead(<variable>, <variable>, ...)

Posted: Mon Apr 19, 2010 10:09 pm
by Deth good
Thanks for the example. It makes my point (more compact, more readable code) very clear I think. :wink:

Re: RotaryRead(<variable>, <variable>, ...)

Posted: Mon Apr 19, 2010 10:24 pm
by Kaeru Gaman
well, honestly I think it rather makes clear that you don't need such.

an Array with a counter is such a common thing, it's really really redable and very flexible.

your "RotaryRead" maybe halfways readable, but it's not really flexible.

e.g. when you create your sprites for the animation with #PB_Any, you would need an Array to store the IDs anyways.
... what is easier then, using the array with a counter or passing every single element to your function?

what if the number of frames change?
a function with hardcodes arguments could never cope with that.
for an Array, you would just use a variable for "LastFrame", and be able to alter it any way you like.

honestly, your function is really exotic, I never seen anything like that.
don't count on your function to be implemented.

Re: RotaryRead(<variable>, <variable>, ...)

Posted: Tue Apr 20, 2010 11:01 am
by Michael Vogel
Hm,
even it is more readable, it won't be used by many programmers, I believe...
I have also some wishes about adding functions to PB (mostly integer math functions) to reduce the diversity of codes for the same thing etc. But everything not being implemented can easily be done by you own code, as Kaeru Gaman already wrote – and you can encapsulate these things into procedures as well, so the calling code would be easy enough to read :wink:

Code: Select all

#BufferSize=4

Global Dim Buffer(#BufferSize)
Global BufferPointer=-1

i=0
While i<#BufferSize
	Read Buffer(i)
	i+1
Wend

DataSection
	Data.l 348, 24, 25, 1024
EndDataSection

Procedure.l RotaryRead()
	BufferPointer+1
	ProcedureReturn Buffer(BufferPointer%#BufferSize)
EndProcedure


For i=0 To 9
	Debug RotaryRead()
Next i