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.

DarkBASIC Professional Discussion / change map and back

Author
Message
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 30th Aug 2012 09:33
Hello,

Let's suppose I have a game with a street. I want to enter in a building (bar, shop, ...whatever), for which I have an other map. And after that to go out in the first map, same position, orietnation...

I supose I need to save that position, and to load back, but
which is the best solution to choose for the second map, ..a subroutine, a new executable ....how to do it???
Which are the steps????
Some details pls???

Mihai
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 30th Aug 2012 12:42
The way I do it is I have functions that handle the "world". Here they are:



So to shallowly answer your question, this is how you'd do it (pseudo code):



DestroyWorld() is pretty clear, it just removes all of the data to do with the current world.

CreateWorld() would look something like this:



Hope that helps.

TheComet

"if you don't understand recursion than you probably don't understand recursion." ~Jerico2day
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 30th Aug 2012 14:10
Thank you a lot !!

Mihai
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 30th Aug 2012 14:13
I forgot something:

By world you mean:

- the map??
or
- the map and objects?

Becose if it's only the map, I must delete also all objects, or...

So, what's include in the world?

Mihai
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 30th Aug 2012 15:16
Generally the "world" is defined as everything that is not an entity in your game. For example, the terrain, houses, walls, trees, roads, signs, lamps, barrels, etc. are all things that don't move or do anything, so they are part of the world.

TheComet

"if you don't understand recursion than you probably don't understand recursion." ~Jerico2day
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 30th Aug 2012 15:28
Thank you again, it's good to know, I'm new in dark basic.

Mihai
New World Order
21
Years of Service
User Offline
Joined: 31st Oct 2004
Location:
Posted: 30th Aug 2012 15:47 Edited at: 30th Aug 2012 15:49
what the comet said ^^
Also, you should probably have some kind of array where you store the information of all the *entities* (elements of the game that DO change during the course of the game: characters, items that can be picked up, etc.)
For example: You are in the street, go into the building, kill a bad guy, exit back to the street, enter back into the building. Obviously the bad guy should still be dead! Therefore his position, health, dead-or-alive-status etc should NOT be stored along with eg. the position of the walls, furniture etc. (things that don't change). If you had loaded the bad guy along with the world, he would probably be alive "again", every time you re-enter that location.

For my projects I like to keep two kinds of data storage:
Game"data" and Game"states".
"Game Data" contains all the *static* things of the world, variables that can never change:
Where are the walls? where are trees? what is the ambient light level of the location? which characters, items, doors etc *exist*?

a "Game State" contains all the data that can change during gameplay:
Is this door open or closed? Where is this character *right now*? How many Hitpoints does this character have? Has this item picked up already?

The advantage is, that when you want to implement savegames, you only need to store the "Game state", and not the all the static data that remains the same all over the game, reducing the file size of a savegame alot.

hope this wasn't too confusing ^^
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 3rd Sep 2012 04:19
Wow, ThE cOmEt you never cease to amaze me buddy...

I suppose the next question coming along is how to do this in real time instead of a loading screen... and my answer to that is unsynced object handling... I am currently working with this and I am yet to decide what to do with my findings... but I am sure someone will find a non-STYX based solution...

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 4th Sep 2012 01:14 Edited at: 4th Sep 2012 01:15
Quote: "The advantage is, that when you want to implement savegames, you only need to store the "Game state", and not the all the static data that remains the same all over the game, reducing the file size of a savegame alot."


Instead save only what's changed from the original state of the world. Then when it comes to loading, you load the original states and update it with the saved states. Say we've got 100 doors in the world. The original state of the world is all the doors are closed. If we open 1 door and save the game we only save the door and it's state. Since 99 of the doors are closed in the original state of the world which is what will be loaded anyway, there's no point in saving anything that contains the exact same information as it's original state.

Now to add to this, you also need to save events that affect how the world is loaded. For instance, if a room becomes locked and you can't ever go back into it, nothing in that room needs to be loaded. Easiest way to do this is set up the object so it will become unavailable when an event is triggered. This will stop it from being loaded.
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 4th Sep 2012 08:10
Thank you very much, now I understand better how to do it..!!

Mihai
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 17th Sep 2012 16:42
Hello,
I'm back with a question:

I tried to delete the world...and I have errors with the object created in the world, and which are moving inside the Do-loop cycle......or change coordonates...size..

What can I do with the do-loop?..I tried to exit from do-loop.but close the game...

Mihai
The Weeping Corpse
14
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
Posted: 17th Sep 2012 20:29
All the above are correct. I just wanted to say that New World Order made me chuckle with

"variables that can never change:"



mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 22nd Sep 2012 09:11
I know I'm a newbie, but still I know "the variables are changing..", if not, are NOT VARIABLES, ARE CONSTANTS...

So, please let me know the principle of how to do it...probably I will establish a name for all variables, for instance "object"..??, and to work with that name in do -loop???

a pseudo-code will help.

Thank you in advance !!

Mihai
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 22nd Sep 2012 16:50
Quote: "I tried to delete the world...and I have errors with the object created in the world, and which are moving inside the Do-loop cycle......or change coordonates...size..

What can I do with the do-loop?..I tried to exit from do-loop.but close the game..."


Can you post your code so we can have a look at it? Make sure to put it inside code snippets by placing these tags around your code:

[[b]code][/b] (Put your code here) [[b]/code][/b]

TheComet

"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 22nd Sep 2012 18:49
Here I put part of inside do-loop code



Mihai
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 25th Sep 2012 09:35 Edited at: 25th Sep 2012 09:35
I don't see any map loading in your code...

One thing I noticed is this:



Here is a much more efficient way of doing that:



Or you could even compress it down to this:



You don't need abs() because a^2 will always be positive. (-4)^2 = 16, abs(-4)^2 = 16. See, you don't need abs().

The function sqrt() is really slow, so it's faster to square the other side of the equation:

sqrt(3^2 + 4^2) = 5
3^2 + 4^2 = 5^2


TheComet

"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 27th Sep 2012 15:22
I wanted to show you only what I have in the do-loop, if I mention an object to which I calculate the distance, in the do -loop cycle, like here :





When I delete the world, I have an error and ask me don't find the object 3400+i.....that was my question, what to do with the objects in do-loop...change whit variables??and how???

Mihai
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 27th Sep 2012 15:40 Edited at: 27th Sep 2012 15:41
So if I'm correct, your still trying to retrieve object data when it's been delete and that would be the problem.

For instance. Say in my loop all I have is x# = object position x(1), so every frame it will check object position x. So what if I delete object, soon as the loop cycles again it try's check the object, it will throw an error because object 1 doesn't exist, hence the command we'll use object exist(id).

So now we have:
if object exist(1)
x# = object position x(1)
endif


And this will stop the error.
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 27th Sep 2012 18:18
Than k you very much, I supposed that, but i needed a confirmation..

Mihai

Login to post a reply

Server time is: 2026-07-08 00:24:57
Your offset time is: 2026-07-08 00:24:57