Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Make your own code/command? (Help Needed)

Author
Message
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 11th Aug 2010 02:48
Is this possible? Say if I wanted to make a command in darkbasic pro like
create object "objectpath\object.x",objnumber,objx,objy,objz
which would do the same as
load object "objectpath\object.x"
position object objnumber,objx,objy,objz

Is it possible to do something like that?
If it is how would I go about doing it?

I want coke, not Pepsi!
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 11th Aug 2010 02:57
Easiest way would probably be functions. It would look something like this:


Place this after the END command in your main source file (or one you included using #INCLUDE) and then you can put Create_Object("Plane.3ds",1,43,26,953) to load the object Plane.3ds as object 1 and place it at coordinates 43,26,953.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 11th Aug 2010 03:36 Edited at: 11th Aug 2010 03:37
I tried this code

but I get an error here: x=posx(1)
and 2 other questions:
1. Is this how DLLs are made?
2. Does this slow down your game or speed it up?

I want coke, not Pepsi!
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 11th Aug 2010 03:46
You would do it something like this:


Though that's a pretty pointless function...

"everyone forgets a semi-colon sometimes." - Phaelax
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 11th Aug 2010 04:24 Edited at: 11th Aug 2010 04:26
@Zoto I just want to try functions it was an example for me to try.
Anyway can you explain what that code does? Like why do you have to make pos local and a float? and whats the difference between posx(objnumber)
object position x(objnumber)
comapared too
pos = object position x(obj)
and at the end why do you have to endfunction pos instead of just endfunction?



EDIT: I now have an error here, its a syntax error and it highlights all of it


I want coke, not Pepsi!
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 11th Aug 2010 06:12
I was having problems with the code above so I tried a simple code and it doesn't work! It says theres an error with

this is my code


I want coke, not Pepsi!
Devonps
15
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 11th Aug 2010 10:10
When you create a Function with incoming parameters you have to define the data type for those parameters.

As in this example...


Hope this helps,

Steve.

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 11th Aug 2010 11:27
@Steve

How does that work with this function? I don't understand that




I want coke, not Pepsi!
Devonps
15
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 11th Aug 2010 11:56
Your code would become



BTW: You don't need the brackets on your make object cube command.

Note: If you're struggling with the basics of data types maybe you should read the tutorials or at least look at the help file that comes with the editor (press F1 from within the editor), this would help you quite a lot.

Hope this helps,

Steve.

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 11th Aug 2010 20:32 Edited at: 11th Aug 2010 20:48
@Devonps
Thanks! But my only real problem was having bracets around the make object cube thing I think. This is my working code now, I added basic movement along x and z and also added text showing where the cube is along x and z. I had to use a do-loop because otherwise it would show an error with a function mid program.

My code:


I want coke, not Pepsi!
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 11th Aug 2010 20:49
When calling a function you have written, you need the brackets. When you invoke a DBP command, you don't need the brackets (unless it's returning a value, such as str$()).

"everyone forgets a semi-colon sometimes." - Phaelax
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 11th Aug 2010 21:02
ok thanks Zoto will try to remember

I want coke, not Pepsi!
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 11th Aug 2010 21:53
To your question, it's possible.How you can do it?Look at this Code Snippet how i do it.Here:

http://forum.thegamecreators.com/?m=forum_view&t=171243&b=6

I have added few more commands to this like setfps, delete_objects and few more but i'm lazy to edit this now.Tommorow maybe i'm gonna update the snippet.

Coding is My Kung Fu!
And My Kung Fu is better than Yours!
ghostkrashers
14
Years of Service
User Offline
Joined: 19th Jul 2010
Location:
Posted: 12th Aug 2010 04:55
cant you just create a function? Just like this:

`lets call it thing
Function Thing()
`Then your function goes here
EndFunction
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 12th Aug 2010 07:05
@ghostkrashers
that's what this is.


I want coke, not Pepsi!
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 12th Aug 2010 07:11
Hey I have a problem, I was trying to make the right and left keys move and change the player but now they both are just invisible.



Also ProF what are those cubes in the background for?

I want coke, not Pepsi!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Aug 2010 08:34
When you want to do multiple things in an IF/THEN statement you can drop the THEN and use ENDIF to stop the IF check.




Really you shouldn't be deleting the sprite over and over again because all you need to change is the image number the sprite uses.



CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 12th Aug 2010 08:39
Thanks works now, do the cubes in the background matter?


I want coke, not Pepsi!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Aug 2010 08:59
The only object you really need is the player object but only if you want to continue to use a plane. Sprites still use 3D planes but you don't have to specifically make a plane first to use a sprite.

Here's your code with no "normal" 3D stuff:


CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 12th Aug 2010 09:25
Quote: "The only object you really need is the player object but only if you want to continue to use a plane. Sprites still use 3D planes but you don't have to specifically make a plane first to use a sprite.

Here's your code with no "normal" 3D stuff:"


yeah but with that code the camera doesn't follow the player, also how would I do collision WITHOUT using camera collision with the old code?

I want coke, not Pepsi!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Aug 2010 09:56
Quote: "yeah but with that code the camera doesn't follow the player"


Most games where the player is always at the center of the screen the camera doesn't follow them since they never really move from the center but rather the background moves instead. Like in old 2D Mario games the only time he actually moves is when he's traveling to the center of the screen. After that he stays in place and the background moves. Place the sprite in the center of the screen with a fixed x and y coordinate and it'll stay there.

Quote: "how would I do collision WITHOUT using camera collision with the old code?"


You can use SPRITE COLLISION to detect when your player sprite hits another sprite. With SPRITE COLLISION if you use a zero for the target sprite then it'll return the first sprite number that's hitting the sprite your checking.



CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 12th Aug 2010 10:05 Edited at: 13th Aug 2010 02:50
Quote: "Most games where the player is always at the center of the screen the camera doesn't follow them since they never really move from the center but rather the background moves instead. Like in old 2D Mario games the only time he actually moves is when he's traveling to the center of the screen. After that he stays in place and the background moves. Place the sprite in the center of the screen with a fixed x and y coordinate and it'll stay there."

thats kind of over-compliated, I liked the plane way. And then maybe when my sprite hits something it stops the sprite AND the plane from moving which also stops the camera? Is that possible?


Also how could I add a command thats like solidsprite(spritenumber,solid=1/notsolid=0)
then I could just check if the sprite im colliding with is solid

I want coke, not Pepsi!
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 13th Aug 2010 00:09
Bump

I want coke, not Pepsi!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 13th Aug 2010 18:13
Quote: "thats kind of over-compliated, I liked the plane way."


That may be but it's the normal way of doing things in 2D platformers but it really doesn't matter if you use a 3D plane or a sprite to make a 2D platformer.

http://en.wikipedia.org/wiki/Platform_game


Quote: "And then maybe when my sprite hits something it stops the sprite AND the plane from moving which also stops the camera? Is that possible?"


Yes, there is a similar command in 3D called OBJECT HIT. But you have to decide if you want your level made up of 3D planes or sprites because whatever you decide will determine how you detect collision.

Quote: "Also how could I add a command thats like solidsprite(spritenumber,solid=1/notsolid=0)
then I could just check if the sprite im colliding with is solid"


No, but you can use HIDE SPRITE to not show the sprite (if it got destroyed in the game) and SPRITE VISIBLE to check if it's hidden or not before you check for collision of that sprite.

CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 13th Aug 2010 21:30
Quote: "That may be but it's the normal way of doing things in 2D platformers but it really doesn't matter if you use a 3D plane or a sprite to make a 2D platformer.

http://en.wikipedia.org/wiki/Platform_game"


Thanks

Quote: "
Yes, there is a similar command in 3D called OBJECT HIT. But you have to decide if you want your level made up of 3D planes or sprites because whatever you decide will determine how you detect collision.
"


I meant an invisible 3d plane always where my sprite is so the camera can follow it then I could simply when the sprite hits something else it stops them both.


Thats not really what I meant, I meant a varible solid (even if its 1 or 0 it will be visible) but if it's solid I could have a collision detection.

I want coke, not Pepsi!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 13th Aug 2010 23:22
Quote: "I meant an invisible 3d plane always where my sprite is so the camera can follow it then I could simply when the sprite hits something else it stops them both."


Yes it's possible.

Quote: "Thats not really what I meant, I meant a varible solid (even if its 1 or 0 it will be visible) but if it's solid I could have a collision detection."


In Darkbasic if you grab an image of only a black background that image and a sprite created with that image will not be seen because black is transparent yet can still detect collision because the image and sprite still exist even though they are not technically "solid". So, what do you mean by "solid"?

CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 13th Aug 2010 23:39 Edited at: 13th Aug 2010 23:40
Quote: "In Darkbasic if you grab an image of only a black background that image and a sprite created with that image will not be seen because black is transparent yet can still detect collision because the image and sprite still exist even though they are not technically "solid". So, what do you mean by "solid"?
"


By solid I meant a variable that I could use for collision. Anyway does ray collision work with 2d?

Like intersect sprite or something? and I have sparkys

I want coke, not Pepsi!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 14th Aug 2010 02:47
Quote: "By solid I meant a variable that I could use for collision. Anyway does ray collision work with 2d?"


Yeah, you can use any variable for collision. If you keep using a 3D plane you can use ray casting. I doubt there is an intersect sprite command since sprites are generally only used in 2D.

CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 14th Aug 2010 03:54 Edited at: 14th Aug 2010 05:12
ok, but can a 3d plane detect for 2d objects?
I'm just making this collision code off of the top of my head, would it work? (sprite 1 being a player 2-5 being walls)



that code might work if I defined width and height, how might I do that?

I want coke, not Pepsi!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 14th Aug 2010 20:01 Edited at: 14th Aug 2010 20:02
Quote: "ok, but can a 3d plane detect for 2d objects?"


No, sprites are different than 3D objects. It's either sprite collision or 3D collision not both.

Quote: "I'm just making this collision code off of the top of my head, would it work?"


Not really. With SPRITE HIT() it registers a hit when the sprites touch... after that it registers a SPRITE COLLISION() because the sprites are overlapping but not a SPRITE HIT() since their no longer just touching.

Quote: "that code might work if I defined width and height, how might I do that?"


You can't define the width and height of a sprite the way you want because normally the sprite size is determined by the image size. You can use LOAD IMAGE to use a pre-made image or use GET IMAGE to grab one you've drawn/manipulated in code.

The way you want to do sprite collision is a bit off. It allows the player to move till it registers a hit and it makes can_move false. But because the players movement is within an IF/THEN condition that checks if can_move is true the player can never move away from the sprite hit. Once it's false it can never be true again.

Here's one way for it to work:


CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 15th Aug 2010 23:37 Edited at: 16th Aug 2010 00:19
Ok, would this work? is there a way to make a 2d box on DBpro not 3d? so you can choose the height and width then I could just make it invisible and use it for my characters collision?

Oh yeah and is the FUNCTION command how DLLs are made?

I want coke, not Pepsi!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 16th Aug 2010 01:34
Technically if you used standard sprite collision it's always going to be a box around the image no matter what the image looks like.



The above code creates a big box with a 50 pixel border of black around it... because black is transparent it doesn't show up on the sprite but is still a part of the sprite. Move the small box close to the big box with the mouse and when it detects collision (50 pixels away from the big box) it'll tell you in the upper left corner.

Quote: "Oh yeah and is the FUNCTION command how DLLs are made?"


No, functions are like custom commands you make yourself in code. DLLs are made with other programs like C++.

CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 16th Aug 2010 03:16
uh, how can you make it so its not like 30 pixels away when it detects collision?

I want coke, not Pepsi!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 16th Aug 2010 06:12
Grab it exactly the same size as the box.



CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 16th Aug 2010 06:52 Edited at: 16th Aug 2010 06:54
Thanks its perfect but could you explain the get image command more in-depth? like before it was 0s insead of 50s and 100s where 150s.

I also don't really understand the box command
box 0,0,20,20
it says its supposed to be left top right bottom
wouldnt it be 20 all around if its a box for collision?

I want coke, not Pepsi!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 16th Aug 2010 09:48
Quote: "Thanks its perfect but could you explain the get image command more in-depth? like before it was 0s insead of 50s and 100s where 150s.

I also don't really understand the box command
box 0,0,20,20
it says its supposed to be left top right bottom
wouldnt it be 20 all around if its a box for collision?"


Ah. I had no idea you were that much of a newbie.

The numbers are pixel locations on the screen. If the resolution you use is 640x480 then that means there are 640 pixels horizontally and 480 pixels vertically. The "left,top,right,bottom" is a box with the upper left corners x and y coordinates (x = horizontal, y = vertical) and lower right corners x and y coordinates.

You really need to learn a bit more about the basics of Darkbasic Pro before you go any further working with sprites.

Absorb TDKs tutorials ASAP: http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 16th Aug 2010 20:52 Edited at: 17th Aug 2010 08:57
Quote: "The numbers are pixel locations on the screen. If the resolution you use is 640x480 then that means there are 640 pixels horizontally and 480 pixels vertically. The "left,top,right,bottom" is a box with the upper left corners x and y coordinates (x = horizontal, y = vertical) and lower right corners x and y coordinates."


I knew 80% of that, I just never used get image or box before. I was gonna look over TDKs tutorials 3,4,5,10,12

I've had DBpro for maybe 2 months now and in that time I spent it all in 3D, Hawkblood was a really good help with that .

EDIT 1: never mind
EDIT 2: never mind

I want coke, not Pepsi!
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 17th Aug 2010 06:25
Bump

I want coke, not Pepsi!
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 17th Aug 2010 13:54
What's this?A nevermind bump?

Coding is My Kung Fu!
And My Kung Fu is better than Yours!

Login to post a reply

Server time is: 2024-11-23 11:07:57
Your offset time is: 2024-11-23 11:07:57