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 / Map editor like function

Author
Message
nackidno
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Där solen aldrig skiner
Posted: 9th Jul 2008 17:32
Hi, I'm currently trying to make my first map editor. And I need some help.

I want to have a function (Not programming function, a function in the program) that when the player press the spacekey, a new object is made.

The biggest issue now is, How can I do so that the program handles unlimited numbers of objects. So that I don't have to program EVERY single object I want to have pasted into the game world.

Is there a way to do this? If I get this answer, I might be able to do the rest myself (Hopefully).

Please if you know how to do this, leave an answer here please.

- Elias, Damezean, Nackidno, Wonderboy

AntocGames - http://antocgames.se.nu/
sinisterstuf
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location: Namibia, Southern Africa
Posted: 9th Jul 2008 19:13 Edited at: 9th Jul 2008 19:25
Well I don't think you're specific enough but I have an idea. This idea is probably stupid and bad because I just thought it up right now and you should probably let somebody who is actually good at programming give you a better one. This is my idea:

I'm not sure what you want but let's say your problem is that there need to be unlimited objects which are described by the editor to your game. So you have an array the size of the number of objects currently there which contains details (probably contained within a UDT) about each of your objects right.
So if you have only 3 objects then DIM objects(3) AS MyObjectType or whatever and each one is described by something like:



I hope that's right so far. Then you also have a variable called maxobjects or something which stores how many objects you have which is in this case 3. Then when you make a new object in the editor you INC maxobjects and a little box pops up and asks you to give it info about the object like name, position etc. But meanwhile your program's IF statement has detected that maxobjects has increased so it makes a new array the same size as the old one like: DIM temp(maxobjects-1) AS MyObjectType, copies all the info from the old one into it (using a FOR loop) and deletes the old one. It then makes a new old one like: DIM objects(maxobjects) AS MyObjectType, copies the info back and deletes the array called temp(0). You now have all your previous data in the same array but with an extra space free for you to input info about your new object through the box that popped up on the screen.
This can continue indefinitely.

Well, this was written a bit messily so I apologise. Hopefully it makes sense but if you have a question then either ask. Or use a different method
Was this helpful?

[EDIT]
I just realised that you don't need the maxobjects variable but you're smart so you can easily figure out why not.
I also realised that you might also not actually need the second array (I warned you about my method ) but I'm not sure because I don't actually know what stacks, lists and queses are. Maybe they would be useful in this instance. Ask someone who doesn't suck, they will help you. Or use my method. It will surprise me and make me very proud at the same time.

No, contrary to popular belief my name is not actually 'Sinister Stuff' but 'sinisterstuf', a misspelling resulting from the latter having too many characters with no spaces in between

oh well
nackidno
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Där solen aldrig skiner
Posted: 9th Jul 2008 20:24 Edited at: 9th Jul 2008 20:38
Sorry for not beeing specific, I think I forgot to write what I really wanted. I really don't know why I didn't write it.

Here is what I am aiming to do:

You have a cube, which you move with the arrowkeys, The thing here is that I want the cube to move in a tiles. like the attached picture.


Now to the thing I want working, When I press the spacekey, a new object in the same position will be created. I tried some methods, but they did not work. This is where unlimited objects come in. I want to be able to create as many object as I want, without any restrictions.


I will try your theory Sinister Stuff. If it's not what I want, I would like to thank you for lending me a hand anyways!

EDIT : I'm really confused about your theory, Sinister Stuff. I think I should take an extra lesson in Arrays.

- Elias, Damezean, Nackidno, Wonderboy

AntocGames - http://antocgames.se.nu/

Attachments

Login to view attachments
sinisterstuf
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location: Namibia, Southern Africa
Posted: 10th Jul 2008 01:09 Edited at: 10th Jul 2008 01:12
I am willing to re-explain if you like. What is it that you don't understand?
So... Are you saying that the box is like a cursor which is used to position the next box you create?

EDIT:
and I used to hate arrays, they confused me and I found them unnecesary. And FOR loops too. But now I like them, they're so useful.
Arrays are like watermelons!
Now, what part of my idea don't you get so I can explain it?

No, contrary to popular belief my name is not actually 'Sinister Stuff' but 'sinisterstuf', a misspelling resulting from the latter having too many characters with no spaces in between

oh well
nackidno
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Där solen aldrig skiner
Posted: 10th Jul 2008 01:58
Quote: "Are you saying that the box is like a cursor which is used to position the next box you create?"


Exactly.

I don't really get anything of your idea. I'm currently learning more about Arrays as I write this. I will look over your idea as soon as I feel confident with arrays.

- Elias, Damezean, Nackidno, Wonderboy

AntocGames - http://antocgames.se.nu/
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 10th Jul 2008 03:37 Edited at: 10th Jul 2008 03:43
You could use a variable, keep increasing it, and check to see if an object of that number exists. If not, then we can use that object number. Have a look at this code. My remarks kinda continue onto the next line so they can all be read.



The method shown here is simple but effective. Some people use more complex methods with arrays, but I won't go into that. It's commonly referred to as a "Free Object" function because it tells you the "free" or avaliable object number.

Here's the same code, only a function is used to get the "Free Object" this time...



Moe
18
Years of Service
User Offline
Joined: 1st Apr 2006
Location: Sunny California
Posted: 10th Jul 2008 10:00
I'm bored right now so... lemme make a program that goes above and beyond what you're trying to do.

parrot
Moe
18
Years of Service
User Offline
Joined: 1st Apr 2006
Location: Sunny California
Posted: 10th Jul 2008 11:05 Edited at: 10th Jul 2008 11:54


It should work.... but when you press the spacebar to make a new object, it just crashes. But - lemme explain all the commands used. i'll cover arrays first.

DIM arrayname(number of rows)
This command creates an array. DIM abcd(3) would create a table 1 row wide, and 3 rows down, with 3 points of data
0
0
0

DIM abcd(3,3) would create a table 3 rows wide, and 3 rows down, with 3*3, or 9 points of data
0 0 0
0 0 0
0 0 0

DIM abcd(3,3,3) would create a table 3 rows wide, three rows down, and 3 rows deep. You can't show it, because it's three dimensional. But this would create 27, or 3^3 (three to the power of 3, the number of dimensions) points of data.

DIM abcd(3,3,3,3) would create an array 81, (three to the power of four) points of data, and
DIM abcd(3,3,3,3,3) would create an array with 243, or 3 to the power of 5 points of data.

I've only ever used a one dimensional array, but you can have up to five dimensions, no more.

Types:
Types are incredibly useful. From my point of view, they add more dimensions.

type
health as integer
dead as boolean
damage as integer
endtype

DIM player(3)

player(1).health=100
player(1).dead=0
player(1).damage=20

player(2).health=9
player(2).dead=1
player(2).damage=25

player(3).health=100
player(3).dead=1
player(3).damage=200

Player one has 100 health, isn't dead, and has a damage of 20
player two has a health of nine, is dead, and a damage of 25
player three has 100 health, is dead, and a damage of 200

Types store different values for each point on the table.
Now, this table of 1 wide, and three deep, has three variables stored for each of the points on the table. In essence, it is an easier to use, easier to read, two dimensional table of 3,3.

You can also have types within types

type vector
x as float
y as float
z as float
endtype

type object
color as dword
size as integer
name as string
position as vector
endtype

DIM potato(2)
potato(1)color=rgb(13,123,4)
potato(1).size=3
potato(1).name="'Tater"
potato(1).position.x=2
potato(1).position.y=5
potato(1).position.z=3

potato(2)color=rgb(133,13,45)
potato(2).size=4
potato(2).name="Hash"
potato(2).position.x=4
potato(2).position.y=2
potato(2).position.z=1

aaand types within types within types if you want but... i don't wanna go there.

array insert at bottom object

array insert at bottom is the command, object is the name of the array. It creates another point of data at the bottom... i'm not quite sure where it inserts the new number on 2d+ arrays, but

dim yahoo(3)
array insert at bottom yahoo
yahoo(4)=2
print str$(yahoo)
`str$ turns numbers into strings, optionally, str$(variable, decimal places)

Speaking of which, integer types, im sure you know about most of them, but why did i put color as a double word variable? (DWORD)
a word variable has 16 bits, which is how much is needed to store a color for a 16 pit, 32,000 color screen. A 32 bit screen, what most people have, has around 16,000,000 colors. If a word is 16 bits.... then what's a double word?
RGB returns the value of the color in it's 32 digit 1010010101010... (machine code) form, based on it's red,green, and blue components...

AAAnnyways, the command
GLOBAL abcdsljf
creates a variable that will be accessable anywhere in the program. I put
as integer
after them, because, even though im pretty sure variables always start out as integers, its just a habit.

Keystate is an annoying but necessary command. Instead of typing in
if A key()=1
you have to type in
if keystate(30)=1

Basically, from top left starting at squiggly, to bottom right ending at CTRL, you count. the one key is two, three is four, w is seventeen, zkey is 43.... etc... etc...

parrot
nackidno
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Där solen aldrig skiner
Posted: 10th Jul 2008 13:51
@60[] - I did something similiar at first, it did't work though. But I tested your idea and it worked just fine. I will experiment with it until I feel it's right. Thanks!

@Moe - Thanks for that quick explanation of Arrays, it might come to use.
You example on the other hand, crashed when I pressed spacebar or left mouse button. But I learned some new things out from it, I'm greatful!

We'll see how this goes, I'll report back if I got a problem which I can't solve.

//Nackidno

- Elias, Damezean, Nackidno, Wonderboy

AntocGames - http://antocgames.se.nu/
Moe
18
Years of Service
User Offline
Joined: 1st Apr 2006
Location: Sunny California
Posted: 10th Jul 2008 22:56
yeah, i can't figure out why it crashed either, i'm sure it's a problem with the array...

parrot
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 13th Jul 2008 00:00 Edited at: 13th Jul 2008 00:00
@nakidno: You're welcome . Make sure to store the object numbers in an array of some sort so you can refer to them later.

Login to post a reply

Server time is: 2024-09-27 18:15:10
Your offset time is: 2024-09-27 18:15:10