Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - SBlectric

Pages: 1 2 3 [4]
46
Off Topic / Re: Create your own robot
« on: 2011-Dec-27 »
That looks neat

47
Off Topic / Re: Merry Christmas Guys!
« on: 2011-Dec-27 »
Merry Late Christmas!

48
Code Snippets / 3D Distance
« on: 2011-Dec-27 »
2nd post...
For any 3D game you need to know the distance between two objects, there is this function I made:

Code: (glbasic) [Select]
FUNCTION Distance3D: x1,y1,z1, x2,y2,z2
RETURN SQR( POW(x2-x1,2) + POW(y2-y1,2) + POW(z2-z1,2) )
ENDFUNCTION

Enjoy!

49
My first post! Woo!  :D

When I call GETCOMMANDLINE$() the commands are separated by either quotes (if they contain spaces) or just by spaces. Here is a function that will separate each one into elements of an array.

Check it out.  =D

Code: (glbasic) [Select]
FUNCTION CmdLine: cmd$,e$[]

LOCAL a%,b%,exit%,pos%,endpos%

cmd$=REPLACE$(cmd$,CHR$(92),"/")

DIM e$[0]

WHILE 1

IF pos>LEN(cmd$)-1 THEN BREAK

SELECT ASC(MID$(cmd$,pos,1))

CASE 34 // if the value is an open quote

b=INSTR(cmd$,CHR$(34),pos+1)
IF b<pos+1
endpos=-1
exit=1
ELSE
endpos=b-1-(pos)
ENDIF

DIMPUSH e$[],MID$(cmd$,pos+1,endpos)
pos=b+1


CASE 32 // if it's a space
INC pos,1


DEFAULT // if it's any other character

b=INSTR(cmd$,CHR$(32),pos)
IF b<pos+1
endpos=-1
exit=1
ELSE
endpos=b-1-(pos-1)
ENDIF

DIMPUSH e$[],MID$(cmd$,pos,endpos)
pos=b


ENDSELECT

IF exit THEN BREAK
WEND

ENDFUNCTION


Pages: 1 2 3 [4]