Mirage Engine
[Misc] Some useful functions... - Printable Version

+- Mirage Engine (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Source Code Development (https://mirage-engine.uk/forums/forumdisplay.php?fid=51)
+----- Forum: Mirage Source 4 (Visual Basic 6) (https://mirage-engine.uk/forums/forumdisplay.php?fid=44)
+------ Forum: Tutorials (https://mirage-engine.uk/forums/forumdisplay.php?fid=13)
+------ Thread: [Misc] Some useful functions... (/showthread.php?tid=2175)



[Misc] Some useful functions... - JokeofWeek - 23-09-2008

Hey guys Smile Here are just a few useful functions I've made lately Smile Enjoy Big Grin

[code]Public Function IsInRange(ByVal TestX As Integer, ByVal TestY As Integer, ByVal X As Byte, ByVal Y As Byte, ByVal Range As Byte) As Boolean

IsInRange = False

TestX = Sqr(((TestX - X) * (TestX - X)) + ((TestY - Y) * (TestY - Y)))
If TestX


Re: [Misc] Some useful functions... - Jacob - 10-10-2008

Quick question

Shouldn't the AddInt and AddLong be like this:
Code:
Public Sub AddIntegerToSetBuffer(ByRef Buffer() As Byte, vData As Integer, ByRef WriteHead As Integer)
  
  Call CopyMemory(Buffer(WriteHead), vData, 2)
  WriteHead = WriteHead + 2
End Sub
Code:
Public Sub AddLongToSetBuffer(ByRef Buffer() As Byte, vData As Long, ByRef WriteHead As Integer)
  
  Call CopyMemory(Buffer(WriteHead), vData, 4)
  WriteHead = WriteHead + 4
End Sub

Otherwise:
Code:
Public Sub AddIntegerToSetBuffer(ByRef Buffer() As Byte, vData As Integer, ByRef WriteHead As Integer)
  Dim tBytes() As Byte

  ReDim tBytes(UBound(Buffer))
  
  Call CopyMemory(tBytes(WriteHead), vData, 2)
  
  Buffer = tBytes

  WriteHead = WriteHead + 2
End Sub

You'd be overwriting anything you've written to the Buffer() before that call because it's setting Buffer = tBytes. tBytes is never given the data from Buffer.


Re: [Misc] Some useful functions... - JokeofWeek - 10-10-2008

Dugor Wrote:Quick question

Shouldn't the AddInt and AddLong be like this:
Code:
Public Sub AddIntegerToSetBuffer(ByRef Buffer() As Byte, vData As Integer, ByRef WriteHead As Integer)
  
  Call CopyMemory(Buffer(WriteHead), vData, 2)
  WriteHead = WriteHead + 2
End Sub
Code:
Public Sub AddLongToSetBuffer(ByRef Buffer() As Byte, vData As Long, ByRef WriteHead As Integer)
  
  Call CopyMemory(Buffer(WriteHead), vData, 4)
  WriteHead = WriteHead + 4
End Sub

Otherwise:
Code:
Public Sub AddIntegerToSetBuffer(ByRef Buffer() As Byte, vData As Integer, ByRef WriteHead As Integer)
  Dim tBytes() As Byte

  ReDim tBytes(UBound(Buffer))
  
  Call CopyMemory(tBytes(WriteHead), vData, 2)
  
  Buffer = tBytes

  WriteHead = WriteHead + 2
End Sub

You'd be overwriting anything you've written to the Buffer() before that call because it's setting Buffer = tBytes. tBytes is never given the data from Buffer.

Ah true, fixed Smile Thanks Dugor Smile