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

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Deth good
User
User
Posts: 19
Joined: Wed Apr 27, 2005 7:34 pm
Location: Netherlands

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

Post 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
...
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

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

Post by Kaeru Gaman »

:?: what should this help for?
oh... and have a nice day.
Deth good
User
User
Posts: 19
Joined: Wed Apr 27, 2005 7:34 pm
Location: Netherlands

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

Post by Deth good »

In my case (I code retro games) It would certainly make my code more more compact and more readable.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

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

Post 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.
oh... and have a nice day.
Deth good
User
User
Posts: 19
Joined: Wed Apr 27, 2005 7:34 pm
Location: Netherlands

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

Post 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.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

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

Post 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
oh... and have a nice day.
Deth good
User
User
Posts: 19
Joined: Wed Apr 27, 2005 7:34 pm
Location: Netherlands

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

Post by Deth good »

Thanks for the example. It makes my point (more compact, more readable code) very clear I think. :wink:
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

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

Post 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.
oh... and have a nice day.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

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

Post 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
Post Reply