Multi-Resolution Game Development With GameBuilder Studio Check it out!
NEW Version 0.9.7 has arrived! New Blazing Fast Particle Engine & More Game Actions. Check it out
How To Use the Find In Range Action?
  • I am trying to using this method in GBS so that I can send one object towards another. If I use Find object in Range, this only appears to work when setting the for each object setting. As I want the object to head to a series of cloned objects randomly this is not good. 

    Can someone please advise if a) this is the correct way of doing what I am trying to achieve and b) if not how but if I am using the right method how to do I get this to work ?
  • 32 Comments sorted by
  • Can any one help me with this ? 
  • @TimCS If you want to find the closest object in range the Find In Range action is your best option. What you will need to do is store the currently found object by accessing the actions' global "CurrentActionData" property. The Find In Range action is triggered continuously every frame so it is constantly searching for the closest object. So if a new object comes within range and it is closer than the previously found object the value of the "CurrentActionData" will change. 

    So if you want to find an object and then lock onto that object to determine a heading you will need to store a reference to the found object when the Find In Range action finds it. You can do this two ways. Store the name and then access the entity directly via an expression later or store an actual reference to the entity object directly in a property. I will explain the later because the second method can cause a memory leak if you forget to clear the reference later. 

    When the Find In Range action finds the closest object have it set a custom property called "targetFound" to true. Also have it store the entity name (Game.CurrentActionData.foundEntity.name) to a variable called "targetEntityName". Make sure you store the entity name first before changing the "targetFound" property to true. Setup a rules component that checks if the "targetFound" property is true and if it is then trigger an action to read the current position of the target entity that was found by using an expression to access the entity by name: Entity[targetEntityName].Spatial.position. You can then take that position value to determine where your object needs to move to.

    Whenever you want to change the current targetEntity just change the targetFound property to false and trigger the Find In Range action again to perform another search. It is a good idea to put the Find In Range action under a rules component that checks for a property like currentlySearching. Just so that you can turn searching on and off. You don't want to just have Find In Range running the whole time unless you need to.

    Hope this helps. Every aspect of GBs will be documented in tutorial form one feature, action, and component at a time. That is a major goal of ours for this year.
  • @Lavon

    Much appreciated for coming back to me on this and for providing this information I will look into this and let you know :)
  • @Lavon
     
     
      With "Find in Range" what I am best to use for the Entity Type and Object type boxes ? and how would I best calculate the search distance as from the object that is moving towards the target ? 

    Also how to I best go about setting the targetFound boolean to true ? is this done as part of the Find In Range  action ?

    ** EDIT ** ** UPDATE **

    Still cannot seem to get this to work (it will probably be something I am doing wrong)

    Find In Range is set as follows
    Created a RuleMap Called FindTarget
    Run If is set to All 

    Trigger Actions 
    Find in Range -> Search Mode : A Random Object -> In A Range Of Spatial : @Spatial -> Entity type : Target -> Object Type : target -> Search Distance : 2000
    Per Object Found:
    Group Action : 
      Globals.Data.targetEntityName = Type Reference #Game.CurrentActionData.foundEntity.name
      Sets targetFound = true


    The a further RuleMap to check targetFound :
    Run If All
     When expression -> Self.Properties.targetFound = true 
       Move Toward -> Move Spatial : Spatial (also tried ALL) ->
     To Target Spatial -> tried #Entity[targetEntityName].Spatial.position and      Entity[targetEntityName].Spatial.position and #Entity[Globals.Data.targetEntityName].Spatial.position -> Move Speed : 100

    but nothing happens 

    Please help


  • @TimCS your search distance is whatever you want it to be. It is a radius of how far out you want to search from the current object (Spatial). You are trying to search for the target object so you don't know the distance between the two objects yet so just put a large enough radius to be able to find the target object based on the size of your game. The search distance is in pixels.

    The entity type and object type are both optional. The entity type means you can filter the search to only look for objects that are spawned from another entity in the scene. The object type is a way to filter by tags placed on spatials. You add object types in the Engine settings window and apply them onto a spatial in the spatial properties panel. 

    The expression to access the entity would be: Entity[Globals.Data.targetEntityName].Spatial.position. That can only be done in an expression input field. Not a property reference field. You have to make sure the input field is an expression. Since you are using the Move Toward action there is no expression input on that action. So you will need to store a reference to the found object's spatial directly instead. So instead of storing the entity name store the Game.CurrentActionData.foundSpatial to a property called Globals.Data.targetSpatial. Then pass that Global property to the Move Toward actions'  To Target Spatial input field.

    One good way to test that you are accessing values and or to check values at runtime is to use the Log Output action and print out the value of a property like Globals.Data.targetEntityName to the console. Run your game in debug mode and check the console for the printed value. You open the console at runtime using the "~" (Tilde) Key.

    Also make sure to check for a property on your Search Rules component to only execute if the property currentlySearching is true. Create that custom property and turn it on and off depending on when you want to search.


  • @Lavon

      Thanks again for your input , I am having some "issues" with GBS where by the windows it opens for the various settings either start appearing at the very top of GBS preventing me from moving them down to get to them or in the case today when I opened the action under the Rule Component to change the settings the window has appeared to have shrunk the actions that are listed within and so I cannot get to them or expand this window . This is on the Mac if that makes any difference .

    Got round the above problem as I kept closing an re-opening the windows until they worked. Also I cannot see an option anywhere to run the game in debug mode could you please point me in the right direction

    Also tried as you suggested with the global variables etc but I still cannot see to get the object to move to a target so I am trying to re-add the find in range on this project but now on removing it entirely  and re-adding it, on setting the group action to re-add the settings for the variables brings them back and then I cannot edit them :(  
  • @TimCS we are about to put out a new build which should fix the sizing issue of the group action properties window. 

    To run the game in debug mode open the publish window and scroll to the bottom there should be a dropdown where you can change from production to debug.
  • @Lavon I will have to try and create a new project to see if I can get it to work from scratch. This project really was very simple one circle object and two square objects (the targets) , I decided to remove the filters from within the settings for the target and enemy (the circle) and then to try the find in range without a filter set . This seems to be where the project started playing up. I thought I would let you know what I had done because it may be something to look into for GBS debugging :)

    Secondly the reason why I could not see the debug option, is that the publish window is too long and overlaps the springboard at the bottom of my Mac and there is no scroll bar down the side to get to it. Perhaps this could be added in another build to get to these settings as my Mac is only a 13" screen.just a suggestion :)

    Also just another thought should the object Body Type work with both KINEMATIC and DYNAMIC with find in range and move toward or should it be DYNAMIC with gravity off until it needs to move ?

    ** EDIT 24/1/2016 16:26 GMT **
     So I have re-create the project so far, one circle (the Enemy) and two square objects (the targets at different positions on the screen) the enemy object is what I am trying to move towards one of the randomly chosen square objects . I have created created two global variables (both strings) targetFoundName  & targetSpatial .

     Under the Enemy Object I have created a data container called "Properties" and added targetSearching and targetFound (both boolean) . I set the targetSearching by default to TRUE. 

    On the Enemy Object I created the first rule map called SearchForTarget which is the rule to find the target. So I set an expression for this rule to run only while the targetSearching is true . Then added a trigger action of Find in Range . Search mode is set to A Random Object , in range of Spatial = @Spatial  , Entity type and Object type left alone for now,  entered a large value in search distance of 20000 and on the trigger action chose group actions. Clicked on edit to add to the group actions clicked on the plus button but now I am getting white blank entries that I cannot edit or change 

    This is on a new project now not editing an existing one, clearly an issue with the software. I suspect on coming out and back in may solve this. I know this software is beta, so could this be part of the same problem with the group action window already mentioned before ? 

    ** EDIT 24/1/2016 16:47 GMT **

    Closed GBS down re-opened it and the project and I still cannot add to the group action , it still does the same as mentioned above and even after running the project it makes no difference . Please help :)


    ** EDIT 24/1/2016 22:30 GMT **

    After removing GBS from (this is a Mac BTW) Applications and also under Library/Application Support/GameBuilderStudio and re-installing it, it now appears that the group action (I have not completed with changing the actions yet) is showing the added actions to change. 

    ** IN Addition to above update **
    So I was able to add and set the first action , however on the second or third that I wanted to edit, the window that opens goes right to the top of the GBS window and this then means I cannot drag it down. Perhaps a tilling , bring all to front or some kind of Window management could be added in a future release so that these windows can be brought into view? 

     However this means that at the moment ,I cannot move forward with the development of this game I am trying to make :( . Any suggestions on how I can get around this please ?


       

  • Will I need to wait for these issues to be fix in the next build or is there a way around the problems I have found mentioned in my previous post ?
  • @TimCS, zip up your project folder and send in a dropbox link to it. I will take a look at it to see what may be the issue. Use the contact form on the site to send the link.
  • @Lavon

       Okay will do ,  I will send the latest project as it has happened to others before it as well which I have kept if you need to see those to


  • @Lavon

     
      Have you had any chance of looking at the project I sent please ?
  • @TimCS I did find a bug in the FindInRange action when using random search mode but it does work fine when using search by closest object. Here is the working project. https://s3.amazonaws.com/gbsfiles/movetoTarget.zip A new build is on the way with the fix for this project to work.
  • @Lavon

       If you recall the actual issue I was having was down to not being able to add multiple actions if you read my post above on the 24th Jan you will see what I am referring. So I could not test what you had suggested because I could not add the actions to set the variables
  • @TimCS try the latest build (727) and see if it helps. The windows now open in the middle of the editor.
  • @Lavon

      Sorry for the delayed reply I will try this version out first on my existing project and then creating a new one in case that does not work
  • @Lavon

       I have used the latest available version of GBS but when I go into the group actions and try and add a further action, I just get  white gap where the next action should be and as I add more the same happens. So even though the window is expanding the additional actions are not displayed. 

      This is one of the symptoms that was happening to me before, it either did this or did not add anything to it at all. 
  • @TimCS sorry about this. Working on a new beta build to fix this.
  • @TimCS it looks like this may just be a case of the old app files not being removed properly when GBs tries to unpack the new build. You will need to go to the application storage folder on your machine. It is located in different location depending on if you are on a Mac or Windows. Delete the compiler and the plugins folder and re-run GBs. It should start the installation process all over again. Make sure to use the latest build.
  • @Lavon

      Could you give me a clue where this folder would be on the Mac ? Would the application folder be at the root part of the hard drive or within my user folder ? If I find it in the mean time I will post here to let you know 

    ** EDIT  **

    I have found this folder, is this correct ? :

    /Users/<myuser>/Library/Application Support/GameBuilderStudio/Local Store



    There seems to be a compiler and plugins folder here along with a plugins-external folder as well



    ** EDIT **

    Ended up clearing these folders and the group action is working now. 


    Moving forward, I have gone through the project following your instructions but I must be doing something wrong because the enemy object that is meant to move towards one of the two targets does not move at all.

    When I want the enemy object t move, am I using the Move Toward action or the Interpolate action ? If I am using the Move Toward action, can you please let me know what the reference that I need to use to refer to the  target . In my case the name is held in the global variables which when I double click on it comes up as Globals.Data.targetFoundName

    Thanks

    TimCS
  • @Lavon

      There is clearly still something wrong at the moment with GBS because I have re-opened the project again and went back into the group actions window and now all of the actions that I have added yesterday are not visible as the window has shrunk again and there is no school bar either. 

     Sorry to make this statement but I have been really patient with this software and I am trying to make a game but at this stage it will never happen. I know that this is a beta program but that being said, I have paid for this and currently have not been able to progress with it at all. 

     Please can you address this issue and also help me with this "simple" action of trying to move my enemy object toward a random target object. 

     I am trying to not have to move to other game makers because I really want this program to work for me and I think it has a great deal of power and ease of use and would really like it to go along way. I have tried other gaming engines both free and some with cost and the current process of what I am doing with GBS I can already do with others.

    Regards

    TimCS
  • @TimCS I've sent you a message with the working project already a few weeks ago with the instructions on what needed to be changed to get everything working. Have you taken a look at it yet? I mentioned that you should not use the found target name but actually store the foundTargetSpatial instead which can be passed to the Move Toward action.

    Regarding the group actions window. Earlier you said the editor was working. So what changed? Maybe you can send over your project that is having issues so I can test it to see if it is a corrupt project file or the editor.
  • @Lavon

      Not seen an email from you which address did you use (PM me for that ) and yes I was trying to store the spatial instead of the name. I will look for your email as I know you have two addresses for me .


      Nothing has changed within the project but even if the project had change why would that make any difference to the group window ? I would expect the program (GBS) to be able to cope with any changes in the project as all that is going wrong is the window display itself .

    Sorry if I came across too strong in my last post I am just venting frustration and like I said before I really what your program to work and when I get my head around it all, it is likely that I will be putting the word around for other people to use it. Also I might even put tutorials on my own website when it is up and running to add external support to it. 

    ** EDIT ** 

    Just checked both email account and I cannot see the email you have sent me, can you please resend the email and let me know via PM which address you used. 
  • @TimCS I totally understand it can be frustrating to get things working when your stuck. I thought I sent you the link to the project that I fixed in a PM. I'm going to send you a PM with the link now.

    You are absolutely right the app should show the correct actions in the window when you re-open your project. What I'm asking is what steps are different from when you saw it working the other day. Was it only working with a new project and then failed to show when you tried loading your project? I need to be able to reproduce the steps you took to see the issue so I can diagnose why its happening.
  • @TimCS I would be more than happy to hop on skype with you and do a personal Q&A session of GBs for an hour if it would help you to get going. Maybe I can clarify some things and and answer some questions. Just let me know we can schedule a time.
  • @Lavon
      
       Thanks for re-sending the link , I will download this project and look at what you have done. 
     
      I have hit another issue with the project and to be honest this is an issue I have had before when trying out various different ideas. The issue is that I currently am using one circle (the enemy) and two squares (the targets) and when trying to move one of the squares I cannot highlight it, instead I have to click on the object listed in the layers list. However when doing this, if I want to then move the square, on clicking on it again, it looses focus and stops me from dragging it about.

    Also on the matter of the group actions, the window again, yesterday evening, came back to show all of the actions listed. This again has happened before and should not. 

    ** EDIT **

     On looking at the project you made and after changing mine to store the spatial of the target, I cannot see much of a difference other than I noticed you have set the target found and stop searching flags before setting the spatial name whereas I thought from your previous post here , that storing the name or spatial needed to be done first.

    When I have more time I will look at it again but I really cannot see why my does not work and yours does


    ** EDIT 2 **


      In one of your previous posts you stated to store the spatial as an expression not a reference however in your working project you have used a reference to store the spatial whereas I followed your advice to use an expression this is likely to be why it does not work for me and I quote :

    "That can only be done in an expression input field. Not a property reference field. You have to make sure the input field is an expression"

    If this is not want you meant then it was unclear at the time


    ** EDIT 3 **

     With a lot of re opening these two projects yours and mine, GBS opened both of them incorrectly in that for example at one time your project had no spatial setting against it for the move toward action, then when I re opened it , it then had the spatial set against it . Not really sure what I have done but it appears to be working now however without knowing my changes I am unsure if I will come across the problem again. 

    Secondly when I opened my project , I found that the target objects seem to be set to dynamic not non-moveable static , however when I click away and back to the spatial property then they changed back to non-moveable static. This is the sort of example of the quirks of GBS that really frustrate me because you spend a lot of time getting something working, then when it does not, this kind of issue makes you think it is you at fault, then you spend time correcting something that if clicked out and back it corrects itself but you don't know if it really has set that change.

    Also when opening your project again today the group actions window went to the shrunken state where I could not see the actions, however on coming out and back in again of this window it corrected itself. 

    ** EDIT 4 **


    I have since moved a little forward with this project but I have a question on the matter of the enemy, as at the moment there is just one in this project and I aim to have multiple enemies randomly moving to any of the targets. With that in mind, how would I best deal with the variables that are being used to start the search end the search and those that are currently global to hold the spatial of the target. As there is no know quantity to how may enemies I might have on screen at any one time, I cannot really start creating multiple variables that might not get used. 

     Any ideas ?


  • @Lavon

      I am trying to use the spawn entity action to see if this would work but the drop down option to select an entity does not list any of the objects that I have in this project and I have not used this action before and could not find anything about it in the documentation or any tutorials. 

  • @Lavon

      It seems with GBS that whenever there is a project with the interface, most of the time it requires coming out of GBS and back in again which is counter productive . This is what I had to do to get the entities in my project to be listed in the spawn entity. 


     again as per my previous post, GBS has a lot of potential but until these issues are resolved, I cannot use it to work with this game. I may have to go back to another game maker for now but I still want to use GBS in the long run. Although I will give GBS one final try before I decide to move elsewhere because I really want it to work.

       I have also added to my other post about dragging objects which also needs to be looked into as dragging an object should really be a simple process. In other game makers, this is dealt with by just having a tick box for each object to state whether that object can be draggable. 

    From the post with the edits , please can you read these because some of them indicate problems I have come across in GBS. 

  • @TimCS I understand you're frustrated but this is not the forum or the place to put so many different issues at once under one post. They can't be tracked properly and addressed this way in a comment thread. You have various different issues in this thread and it's called "how to use Find In Range action". It is better to use the support link to report issues you are having with the editor separately so we can fix them and issue a new build with a fix. The only way to get a fix in is to have reproducible steps. Not just, "hey this thing doesn't work". Not saying you do that I'm just saying there needs to be clear steps.

    You are more than welcome to use whatever tool you feel gets the job done and if it is not GBs then maybe it is just not for you, but I guarantee you any program you use will have bugs and issues with it but no other tool fixes issues and delivers new builds on the fly like we do with GBs in such a short amount of time.

    I've offered private support time for you to clear up some of these issues so it is up to you if you want to setup a time to go through the issues you are having. It may be a simple fix or just lack of knowledge on the tool.
  • @Lavon

        Since my posts above I  think I have got the spawn entity working now but I do need to know how to stop multiple instances of the spawned objects going to the same target if you could help with this I would appreciate it. This does all relate to find in range as this what the spawned entities are doing. 

     Also I have noticed that when the spawned entities reach their target they quite often "shake" for a short while, is there anyway to stop this ? If you want me to post these as separate questions I do not mind it is just that I did not want to swamp the forum with loads of different questions all at once. I do however post more that "it does not work" in my posts as I do know about trouble shooting software due to my job :) 

    Yes you have offered private support time via Skype , did you also see my PM on this ?
  • @TimCS This is a bug in the action so we will fix this in the action itself to better check for the stop distance accurately to prevent the shake and it will be in the next build coming out shortly.

    To prevent spawned entities from going to the same target you would need to manage a found targets list. You need to check that list to see if the found target has already been found and perform another search. 

    Or for random searching you could put a property on the target itself called "targetFound" and before you trigger the actions for a found target, nest the actions under a conditional action and check the found target entity for the "targetFound" property to see if its false before executing the actions. If the value is true on a found target then the actions won't be triggered and your search should trigger again and find another random object to check. This of course would only work with a search mode of random. 

    If you choose to search for the closest object then you would need to do this a different way because Find In Range would always return the same object as the closest object if the distance has not changed.
  • @Lavon

     Thanks for this reply very helpful and will look into working this out :) 

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Tagged