Jump to content


Photo

Checking Script Outside_view Not Working


  • Please log in to reply
4 replies to this topic

#1 JishHD

JishHD

    GMC Member

  • New Member
  • 1428 posts

Posted 16 January 2010 - 08:23 PM

Hey all, haven't posted on these forums for a while :P

Anyway, my problem: I have this script that checks if a specific (x,y) coordinate is inside a designated view.

/*
outside_view(x,y,view#)
function: tests if a coordinate is outside the given view
returns: yes (1) or no (0)
*/

if view_xview[argument2]<0 {view_xview[argument2]=0}
if view_xview[argument2]+view_wview[argument2]>room_width {view_xview[argument2]=room_width-view_hview[argument2]}
if view_yview[argument2]<0 {view_yview[argument2]=0}
if view_yview[argument2]+view_hview[argument2]>room_height {view_yview[argument2]=room_height-view_wview[argument2]}

if argument0<view_xview[argument2]
or argument0>view_xview[argument2]+view_wview[argument2]
or argument1<view_yview[argument2]
or argument1>view_yview[argument2]+view_hview[argument2]
{return true} else {return false}

-In my current platformer game, I use this script to check which enemies are currently inside the view when the player targets available enemies.
-I also have a view running that follows the player object through the room.

Here is the code that runs through all objects and checks if it is visible (view is unobstructed) and inside the view:

while (run)
	{
	var halfhyp;
	halfhyp=hypo(view_wview,view_hview)/2 //hypo() finds the hypotenuse of a width and a length
	ins=instance_nearest_visible(view_xview+view_wview/2,view_yview+view_hview/2,obj_trox,obj_block,halfhyp,1)
	//obj_trox is the enemy object, halfhyp is the range to look from the center of the view to scan for enemies
	if !ins break;
	with (ins)
		{
		if !outside_view(x,y,view_current)
			{
			ds_list_add(other.listx,x)
			ds_list_add(other.listy,y)
			instance_deactivate_object(id)
			}
		else
			{
			run=false
			}
		}
	}

And here's a picture of the problem. As you can see, it doesn't select all the available enemies inside the view, just within a certain distance. I'm not sure what is causing this..

Posted Image

[EDIT]
If I remove the !outside_view if statement, then it works great, except it can still find enemies outside the borders of the room if they are within the halfhyp range.


Thank you for any help you can give!

Edited by JishHD, 16 January 2010 - 08:32 PM.

  • 0

#2 ShaManT

ShaManT

    GMC Member

  • GMC Member
  • 228 posts

Posted 17 January 2010 - 02:21 AM

If an object is outside a view, its X value should be lower than view_xview[view] or larger than view_xview[view] + view_wview[view].

And its Y value should be lower than view_yview[view] or larger than view_yview[view] + view_hview[view]

Assume 'view' is the number of view you are using.

I hope that helps.
  • 0

#3 JishHD

JishHD

    GMC Member

  • New Member
  • 1428 posts

Posted 17 January 2010 - 03:58 AM

If an object is outside a view, its X value should be lower than view_xview[view] or larger than view_xview[view] + view_wview[view].

And its Y value should be lower than view_yview[view] or larger than view_yview[view] + view_hview[view]

Assume 'view' is the number of view you are using.

I hope that helps.

Yeah, I know what those do (I made that script haha), which is why I'm still very confused as to why this isn't working correctly..
  • 0

#4 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 18 January 2010 - 02:16 AM

Three things:
  • The width of view is view_wview and height is view_hview. You have mixed up them in a few places, e.g.:

    if view_xview[argument2]+view_wview[argument2]>room_width {view_xview[argument2]=room_width-view_hview[argument2]}

  • view_current is only valid in draw events (which indicates the view currently being drawn.) In other events it has no use and is just 0. You should use the actual view number which the instance is supposed to be in.
  • I formerly examined that deactivating instances inside with() causes some instances get skipped. (Even worse, it causes the entire script start over in a certain case.) You should avoid it; instead, put their id into a list and deactivate them outside the with structure. (Or can't you just use instance_deactivate_region?)

  • 0

#5 JishHD

JishHD

    GMC Member

  • New Member
  • 1428 posts

Posted 18 January 2010 - 04:59 AM

Three things:

  • The width of view is view_wview and height is view_hview. You have mixed up them in a few places, e.g.:

    if view_xview[argument2]+view_wview[argument2]>room_width {view_xview[argument2]=room_width-view_hview[argument2]}

  • view_current is only valid in draw events (which indicates the view currently being drawn.) In other events it has no use and is just 0. You should use the actual view number which the instance is supposed to be in.
  • I formerly examined that deactivating instances inside with() causes some instances get skipped. (Even worse, it causes the entire script start over in a certain case.) You should avoid it; instead, put their id into a list and deactivate them outside the with structure. (Or can't you just use instance_deactivate_region?)

Wow, I feel really stupid now. I thought I caught all those wview/hview mixups, but I guess not. Also it didn't occur to me to just use instance_deactivate_region to deactivate all the obj_trox outside the view, because then I could just run instance_nearest_visible and not even need to use the outside_view script..

Thanks a lot!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users