Jump to content


Photo

Open Source World Map Editor


  • Please log in to reply
11 replies to this topic

#1 ui_dsa

ui_dsa

    GMC Member

  • New Member
  • 105 posts

Posted 16 September 2009 - 08:43 PM

I'm having a problem in making the integration script for my Open Source Map Editor (Link Here).

The Problem:

I have finished almost all of the major aspects of the map editor. Only one major part is left: The warp script, which must do the following:

get_boundary() //which boundary am I on in this map?
Load_world(‘Eden.wrld’)
Find current map’s position on the world map
Then find out which maps are on the border that the player is currently crossing
Input player coordinates, and find out which map to warp the player to
Compare coordinates of the current map in which the player is in with the map that the player is warping to
Account for scale difference between the real maps and the scale models on the map editor.
Plug coordinates of player object in and account for the differences in x and y in the real rooms
Warp!

[b]NOTE: The above is not real code.[/b]

The whole purpose of this map editor and warp script is to allow for rooms to be arranged in relation to one another. Based on this arrangement, the position to warp the player in an RPG when he/she intersects the boundary can be computed.

I have provided the source, as you will need it to solve this problem.
Test Game Source
NOTE: The game will fail if your do not download and put the WRLD File--Download Here in the same folder as the game.

After download, try the following:
1) Go to the right of the start map. Then, try to go back.
2) Go to the bottom of the start map. Try to go back to the original location.
3) Do the same with the left and top.

As you saw, you are able to successfully go down/right, but you cannot go left/up. This is the [main] problem.

How it currently works:

Step 1:
Intersect boundary event in obj_FG2:

//executes scr_warp()
//and implements the results

if scr_warp('Chase_Lite.wrld',obj_FG2)=true 
global.moving=1

//if scr_warp is successfully executed
if global.moving=1
{ //then apply the variables that it set onto the main character
	room_goto(global.rm)
}

Step 2:
Room Start Event of obj_FG2
if global.moving=1
{
scr_applydifference(obj_FG2)
global.moving=0
}

I can't list all of the information about this here, as this post would become too long.

[Important] Information:
obj_FG2=the main character object
global.destx=the x coordinate of the destination that obj_FG2 must go to.
global.desty=the y coordinate of the destination that obj_FG2 must go to.
global.moving=whether or not FG2 has to warp to position (global.destx, global.desty)
global.rm=the name of the room that FG2 must warp to
global.bb=the boundary (1=right, 2=down, 3=left, 4=top)

What I've tried:
1) Checking if the value of global.bb is equal to the correct boundary (It was correct for every single time)
2) Checking if the global.destx/y values were correct for every single warp combination. They were not.
3) Checking if the some of the contents of the 'if' statements in scr_applydifference()
(if global.bb=1 {x=global.destx y=global.desty})
were actually called. Even though the values in global.bb matched correctly, some of them were not called.

What I think the problem is:
The problem is either in scr_warp() or scr_applydifference in the test game.

If you need further explanation of any of the aspects of the problem/scripts, then feel free to ask.

Thanks in advance for your help. :)

Edited by ui_dsa, 14 October 2009 - 12:11 AM.

  • 0

#2 ui_dsa

ui_dsa

    GMC Member

  • New Member
  • 105 posts

Posted 18 September 2009 - 10:08 PM

It has been 2 days without a reply.

Is it really that hard to answer?

If you need additional explanation, let me know.
  • 0

#3 sabriath

sabriath

    12013

  • GMC Member
  • 3147 posts

Posted 18 September 2009 - 10:40 PM

It will take me too long to sort through your code, but just from sight there are a few things you need to consider.

1. The player should have a globalx/globaly coordinate that does not correspond to the current room, it is a global positioning coordinate.
2. When you warp between maps, you use the global position to determine which map to go to, then you subtract out the maps x/y location to get the relative location on that map.


For example, let's say you have a "world" that is 1200 tiles by 1200 tiles, but you split this into 9 sections (3x3 rooms each containing 400x400 tiles). The warp controller object will have a list of all the rooms (or their files if you are loading it externally) and their corresponding (x,y) relation, for example:

room1, 0, 0, 399, 399
room2, 400, 0, 799, 399
room3, 800, 0, 1199, 399
room4, 0, 400, 399, 799
etc.

Now let's say the character is in room3, at position 100,100. His global position would be (900,100). Now let's say that you moved left until you were at (x,y)=(-1,100), which can be checked as being outside the room. The program should then move up to global positioning which would now be (gx,gy)=(799,100), and start going through the list of rooms above, which it will find that 'room2' contains the (799,100) tile (because 400<=799<=799 and 0<=100<=399). The program will then load 'room2' and set the local position to (gx,gy)-(rx,ry) => (799,100)-(400,0) => (399,100), and that becomes the players new (x,y) coordinate on map switch.

Edited by sabriath, 18 September 2009 - 10:42 PM.

  • 0

#4 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1730 posts
  • Version:Unknown

Posted 19 September 2009 - 01:09 AM

I also haven't looked through your code entirely (though I did glance at it), but I thought I would post my own solution to what appears to be the same problem:

http://gmc.yoyogames...opic=419047&hl=

I'm not trying to take focus away from your project, but maybe it can save you some time with the actual engine. I've always wanted to create a world designer for my engine but never had a chance (so you have to arrange rooms by hand in a data structure).
  • 0

#5 ui_dsa

ui_dsa

    GMC Member

  • New Member
  • 105 posts

Posted 19 September 2009 - 02:04 AM

It will take me too long to sort through your code, but just from sight there are a few things you need to consider...


I will definitely keep that in mind, if I decide to rework my integration script from the bottom up (which I will probably end up doing).

I also haven't looked through your code entirely (though I did glance at it), but I thought I would post my own solution to what appears to be the same problem:

http://gmc.yoyogames...opic=419047&hl=

I'm not trying to take focus away from your project, but maybe it can save you some time with the actual engine. I've always wanted to create a world designer for my engine but never had a chance (so you have to arrange rooms by hand in a data structure).


My world map editor doesn't use data structures, but it should be possible (considering the very simple format of my *.wrld files (almost no encryption) ) to integrate it.

I thank you both for your input.

Edited by ui_dsa, 19 September 2009 - 02:01 PM.

  • 0

#6 ui_dsa

ui_dsa

    GMC Member

  • New Member
  • 105 posts

Posted 12 October 2009 - 07:47 PM

It will take me too long to sort through your code, but just from sight there are a few things you need to consider.

1. The player should have a globalx/globaly coordinate that does not correspond to the current room, it is a global positioning coordinate.
2. When you warp between maps, you use the global position to determine which map to go to, then you subtract out the maps x/y location to get the relative location on that map.


For example, let's say you have a "world" that is 1200 tiles by 1200 tiles, but you split this into 9 sections (3x3 rooms each containing 400x400 tiles). The warp controller object will have a list of all the rooms (or their files if you are loading it externally) and their corresponding (x,y) relation, for example:

room1, 0, 0, 399, 399
room2, 400, 0, 799, 399
room3, 800, 0, 1199, 399
room4, 0, 400, 399, 799
etc.

Now let's say the character is in room3, at position 100,100. His global position would be (900,100). Now let's say that you moved left until you were at (x,y)=(-1,100), which can be checked as being outside the room. The program should then move up to global positioning which would now be (gx,gy)=(799,100), and start going through the list of rooms above, which it will find that 'room2' contains the (799,100) tile (because 400<=799<=799 and 0<=100<=399). The program will then load 'room2' and set the local position to (gx,gy)-(rx,ry) => (799,100)-(400,0) => (399,100), and that becomes the players new (x,y) coordinate on map switch.


Sabriath,

I know this is a bit late to do this, but I haven't had time to apply the method you sent me earlier until now.

The Topic you posted the quoted message in (in case you can't remember)

I haven't done the code which makes the player warp from room to room yet; I have only done the calculation part. When I go to the left or top room boundaries, ALL the variables are calculated flawlessly. However, when I go to the right or bottom boundaries, all the variables except the room value (of the room to go to) are calculated correctly. Why is this?


Variables that I am talking about

Important Global Variables:
room_x1[id] =[Array] the x1 coordinate of the room with the specified id (scaled to 1/10, multiply by 10 to get full size)

room_y1[id]= [Array] the y1 coordinate of the room with the specified id (scaled to 1/10, multiply by 10 to get full size)

room_x2[id] =[Array] the x2 coordinate of the room with the specified id (scaled to 1/10, multiply by 10 to get full size)

room_y2[id] =[Array] the y2 coordinate of the room with the specified id (scaled to 1/10, multiply by 10 to get full size)

xcd=the global x coordinate

ycd=the global y coordinate

rm=the name of the room that the player must travel to

destx=the x coordinate that the player must travel to (if going to another room)

desty=the y coordinate that the player must travel to (if going to another room)

i=the id of the room that the player must travel to

Chase Lite--Latest Version



I believe that the problem is in scr_warp() with this piece of code:

var match_found;
match_found=false
//match_found=is the search for a room containing the y coordinates listed above over yet?
//the above is either (true or false)

var i;
//i keeps going up by 1 until the match is found (or i exceeds 15000)
i=0

//searches rooms one by one for a room that the player can warp to
while match_found=0
{
if i<15000 //if i is less than 15000 (the script cannot go on forever) 
	{
	if (10*global.room_x1[i])<global.xcd && global.xcd<(10*global.room_x2[i]) && (10*global.room_y1[i])<global.ycd && global.ycd<(10*global.room_y2[i])
	//if the global x and y coordinates are inside the global coordinates of the specified room,
		{
			//then return that a match has been found!
			//the id of the room is stored in the variable 'i'
			match_found=true
		}
		
			else
		
		{
			//if not, search the next room
			i+=1
		}
	
	}

		else
	
	{
		return false; //returns that there is no room to warp to from the given location (false)
		exit;
	}

}
global.i=i

global.rm=scr_getmapname(i) //takes the value of i and gets the map name from it

global.destx=global.xcd-(10*global.room_x1[i])
global.desty=global.ycd-(10*global.room_y1[i])

Thanks in advance for your help, :)
ui_dsa

Edited by ui_dsa, 25 October 2009 - 05:13 PM.

  • 0

#7 sabriath

sabriath

    12013

  • GMC Member
  • 3147 posts

Posted 12 October 2009 - 08:14 PM

I was thinking more like this:

room_coords[X, 0] = room#
room_coords[X, 1] = x1 (leftmost pixel global coordinate)
room_coords[X, 2] = y1 (topmost pixel global coordinate)
room_coords[X, 3] = x2 (rightmost pixel global coordinate)
room_coords[X, 4] = y2 (bottommost pixel global coordinate)

Where "X" is from 0 to the number of rooms you have in the world map. For example:

Posted Image

The code would then be:

room_count = 3
room_coords[0, 0] = Room_Duskwallow;
	room_coords[0, 1] = 131;
	room_coords[0, 2] = 53;
	room_coords[0, 3] = 160 + 1;
	room_coords[0, 4] = 115 + 1;
room_coords[1, 0] = Room_Barrens;
	room_coords[1, 1] = 69;
	room_coords[1, 2] = 53;
	room_coords[1, 3] = 130 + 1;
	room_coords[1, 4] = 115 + 1;
room_coords[2, 0] = Room_ThousandNeedles;
	room_coords[2, 1] = 69;
	room_coords[2, 2] = 116;
	room_coords[2, 3] = 160 + 1;
	room_coords[2, 4] = 160 + 1;

It would be much easier to use lists, but not many people know how to use them....but those who did can see from an array assortment to translate them into it. Ok, back on track, with the above you would have this for your warping:

//scr_warp(x, y)  where x/y is your global coordinate
//  this will return the index of the array the room is located
//  returns -1 if none found

var i;
for (i = 0; i < room_count; i += 1)
{
	if (argument0 >= room_coords[i, 1]) && (argument0 < room_coords[i, 3])
	{
		if (argument1 >= room_coords[i, 2]) && (argument1 < room_coords[i, 4])
			return i;
	}
}
return -1;

With the index, you now can transform to the following:

index = scr_warp(gcx, gcy);
if (index != -1)
{
	x = gcx - room_coords[index, 1]; //subtracts the leftmost point to 0 out
	y = gcy - room_coords[index, 2]; //subtracts the topmost point to 0 out
	room_goto(room_coords[index, 0]);  //actually move to that room
}

{edit} Just noticed there is a .999999 pixel between each edge that needs to be accounted for...I put a "+1" where you need to adjust, and the formula was changed from "<= room_coords[i, _]" to "< room_coords[i, _]".

Edited by sabriath, 12 October 2009 - 08:29 PM.

  • 0

#8 ui_dsa

ui_dsa

    GMC Member

  • New Member
  • 105 posts

Posted 13 October 2009 - 10:12 PM

I was thinking more like this:

room_coords[X, 0] = room#
room_coords[X, 1] = x1 (leftmost pixel global coordinate)
room_coords[X, 2] = y1 (topmost pixel global coordinate)
room_coords[X, 3] = x2 (rightmost pixel global coordinate)
room_coords[X, 4] = y2 (bottommost pixel global coordinate)

Where "X" is from 0 to the number of rooms you have in the world map. For example:

Posted Image

...


That won't make any difference. The problem is that the room number is not calculated correctly 50 percent of the time. EVERYTHING ELSE is calculated correctly.

Edited by ui_dsa, 13 October 2009 - 10:13 PM.

  • 0

#9 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 13 October 2009 - 11:17 PM

EVERYTHING ELSE is calculated correctly.

How come you are so sure ?

I noticed a certain 'blink' when I moved to one of the 'wrong' rooms, and decided to put a "show_message(...)" in the "room start" event. It revealed that instead of a single "warp" two where executed. When I disabled the "room start" code I got only a single warp ...

What have you done to debug the problem yourself ? Any result-values you can offer us that are unmistakingly wrong ?
  • 0

#10 ui_dsa

ui_dsa

    GMC Member

  • New Member
  • 105 posts

Posted 14 October 2009 - 12:10 AM

EVERYTHING ELSE is calculated correctly.

How come you are so sure ?

I noticed a certain 'blink' when I moved to one of the 'wrong' rooms, and decided to put a "show_message(...)" in the "room start" event. It revealed that instead of a single "warp" two where executed. When I disabled the "room start" code I got only a single warp ...

What have you done to debug the problem yourself ? Any result-values you can offer us that are unmistakingly wrong ?


You probably didn't look at the latest version of the implementation, but that was my fault, as I did not update my 1st post (#1).

I have updated the link now:
Chase Lite-Version 4a
The same WRLD file must still be used.

Still, I might have to check the calculations again. I will do so when I get time.

What I have done to check the debug values:

This image shows most of it, and also see post #6.

NOTE: The new version uses Sabriath's Post #3 method, and only calculates the room coordinates for the jump. It does not actually go to the rooms, however.

The debug values that are wrong in the version that I posted above are the values for global.rm when going to the right/down borders of the room. You see, the world map looks like this:

Posted Image

The values for maps 4 and 5 are computed correctly, but the values for maps 2 and 3 are not.

Thanks for your help,
ui_dsa

Edited by ui_dsa, 14 October 2009 - 12:23 AM.

  • 0

#11 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 14 October 2009 - 09:01 AM

You probably didn't look at the latest version of the implementation,

Actually, I did. I first looked at v4a, and as that did not seem to do anything when I exited the room I took a look at v3.

In v4a there is a small mistake in your "scr_warp" script : you have got "argument1.y" when that should be "argument0.y".

The debug values that are wrong in the version that I posted above <snip>

And where do those "wrong" values come from ?

You see, the world map looks like this: <snip image>

Are you sure ?

Look at , in your "Chase_Lite.wrld", at room 1 and room 4. As far as I can tell they overlap ... (the third argument should be 160, not 1600).

But the actual problem seems to be, in your "scr_warp" script, that multiplying by 10 : You multiply the room-coordinates by 10 but are not doing the same for the players coordinates. That means that, when you calculate those "global.xcd" and "global.ycd" values the player is, according to those values, allways somewhere at the top-left of the room he's trying to get out of (even when he leaves the room at the right or bottom !)

Hope that helps.

P.s.
My debugging (and fixing) in the "scr_warp" script :
PRE

var aa, bb;
aa=scr_trackmapid()
room_caption=string(aa)

bb=scr_getboundary(argument0)
room_caption+="|"+string(bb)

global.xcd=global.room_x1[aa]+argument0.x
global.ycd=global.room_y1[aa]+argument0.y

var match_found;
match_found=false

var i;
i=0
while match_found=0
{
if i<15000 //if i is less than 15000 (the script cannot go on forever)
{
if (global.room_x1[i])<global.xcd && global.xcd<(global.room_x2[i]) && (global.room_y1[i])<global.ycd && global.ycd<(global.room_y2[i])
{
match_found=true
room_caption+="!"+string(i)+" "+string(global.xcd)+","+string(global.ycd)+" "+string(global.room_x1[i])+","+string(global.room_y1[i])+" "+string(global.room_x2[i])+","+string(global.room_y2[i])
}
...

P.p.s.
When your "scr_warp" does not find a room it can move to it will simply exit with an "index out of bounds" error : you defined only 5 rooms, when "i" becomes 6 there will be nothing there (hence the error).

P.p.p.s.
I did not "fix" your game, I only pointed you to the immediate problem. The rest is upto yourself. :lol:
  • 0

#12 ui_dsa

ui_dsa

    GMC Member

  • New Member
  • 105 posts

Posted 25 October 2009 - 02:20 AM

In v4a there is a small mistake in your "scr_warp" script : you have got "argument1.y" when that should be "argument0.y".


I have fixed that in v5. Good point though.

Look at , in your "Chase_Lite.wrld", at room 1 and room 4. As far as I can tell they overlap ... (the third argument should be 160, not 1600).

But the actual problem seems to be, in your "scr_warp" script, that multiplying by 10 : You multiply the room-coordinates by 10 but are not doing the same for the players coordinates. That means that, when you calculate those "global.xcd" and "global.ycd" values the player is, according to those values, always somewhere at the top-left of the room he's trying to get out of (even when he leaves the room at the right or bottom !)


The multiplying by 10 was a result of confusion on my part. I have fixed it now.

P.p.s.
When your "scr_warp" does not find a room it can move to it will simply exit with an "index out of bounds" error : you defined only 5 rooms, when "i" becomes 6 there will be nothing there (hence the error).


I fixed that in v5 by adding a variable called 'global.room_maxnumb'.

However, the problem still persists. I think it has something to do with this clause in my scr_warp:

if (global.room_x1[i])<=global.xcd && global.xcd<=(global.room_x2[i]) && (global.room_y1[i])<=global.ycd && global.ycd<=(global.room_y2[i])
	//if the global x and y coordinates are inside the global coordinates of the specified room,
		{
			//then return that a match has been found!
			//the id of the room is stored in the variable 'i'
			match_found=true
		}
		
			else
		
		{
			//if not, search the next room
			i+=1
		}
	
	}

Well, this is really the only place left for error. I felt that Sabriath's post #3 method was flawless, however, so it should work.

This image shows that the x coordinates of rooms 1, 2, and 4 match in both the WRLD File and the game.

NOTE: To get the x2 value of the room in the game, add the x1 value and the room width together.


Download Version 5 here

Thanks again for your help.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users