News Forums RAIN Sample Projects, How To, and Code Integrating with scripts

This topic contains 10 replies, has 5 voices, and was last updated by  prime 1 year, 8 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #11827

    cdillard
    Participant

    Hello all. I am a brand new newbie to the forums and to using RAIN.

    I understand that the update to RAIN 2.0(other numbers here) has implemented quite a few changes. I have been watching videos and reading and experimenting for a week or so now and I think I’m just screwing something very simple up.

    I just want to figure out how to use variables from scripts inside of RAIN for decisions (for example, as a constraint in a behavior tree), how to alter variables inside a script from RAIN, how to alter variables inside RAIN from script, etc. In essence, how to incorporate my C# code inside of RAIN. I have seen tutorials on the matter, obviously, but I just can’t seem to sift through the RAIN Indie VS Rain 2.0 differences enough to figure out how to do something seemingly so simple.

    Can anyone point me in the direction of some tutorials on this matter? I would greatly appreciate any guidance on the matter. Thank you for your time.

    #11830

    CodersExpo
    Participant

    Basically, you use the AI memory for managing variable data. You can use ai.WorkingMemory.SetItem or ai.WorkingMemory.GetItem to set variable values or get the variables value respectively. Please check out the wiki on memory at http://rivaltheory.com/wiki/doku.php?id=ai:memory:start to get you started. Hope this helps but please let me know if anything is unclear.

    #11838

    cdillard
    Participant

    Ah, Chuck / CodersExpo! I have been watching your videos over and over for a couple days now. You are a good teacher, dude.

    Thanks for the redirect. I will endeavor to check that out and do some testing. Thank you for the prompt response.

    • This reply was modified 2 years ago by  cdillard.
    #11842

    CodersExpo
    Participant

    Thank you much cdillard. I also did quite a bit of the documentation on the wiki, like the page I pointed you to. Please let me know if anything in the videos/wiki are not clear or need further explanation. I’ll see that it gets up-dated

    #11847

    cdillard
    Participant

    Update:

    @CodersExpo: I think the problem was too much documentation, not the lack of, combined with my lack of a clear head over the past week. After going to that link and then subsequent links, ie custom actions, I have successfully managed to get some things working such as setting bools on 3rd party objects, etc. There are some things I am still trying to understand, but if I run into any problems, I will definitely ask. Thank you for your help.

    By saying “too much documentation”, I meant that it was a lot of information I was trying to absorb in a relatively short amount of time. The documentation provided by you guys is superb.

    • This reply was modified 2 years ago by  cdillard.
    #11849

    cdillard
    Participant

    moved my new question to troubleshooting section. Can’t seem to find where to delete my post.

    • This reply was modified 2 years ago by  cdillard.
    • This reply was modified 2 years ago by  cdillard.
    #29522

    Drum
    Participant

    Hi Cdillard.

    Would you mind sharing one or two of the working examples you have for this? I’m struggling with the same problem, getting or setting variables in another script on another object. PM me if you don’t want them public perhaps.

    Thanks

    #32953

    gitoffame
    Participant

    Just wanted to echo the previous post. An example or two would be awesome. I’m having some trouble.

    #32961

    prime
    Keymaster

    Here’s a quick rundown of Memory variables in RAIN.

    By default, RAIN uses a BasicMemory with every AI. BasicMemory stores information accessible to an AI through code or through the Behavior Tree system. Variables stored in memory are specific to each individual AI (i.e., it isn’t a global blackboard.)

    From code, you can get the value of a variable like this:

    ai.WorkingMemory.GetItem<float>("myvariable")

    of course, the method call is Generic, so replace “float” with whatever variable type you are retrieving (string, GameObject, etc.)

    You will set the value of a variable like this:

    ai.WorkingMemory.SetItem<float>("myvariable", 10.0f);

    You will commonly call that code from within a CustomAction in your behavior tree, but really you could call it from anywhere in your own code. You just need access to the AI object. To get that, you would look for an AIRig component.

    AIRig tRig = gameObject.GetComponentInChildren<AIRig>();

    and then it would be

    tRig.AI.WorkingMemory.GetItem<float>("myvariable");

    In the behavior tree itself, you can access variables from any expression field. Expression fields are marked with an “e” symbol. Simply refer to the variable name in the expression field in order to access its value. So in an expression field

    myvariable = 10.0

    or

    myvariable < 10

    would work fine.

    Expression fields in BT nodes exist all over the place. There’s even a node called “Evaluate Expression” which let’s you execute or evaluate any expression you like.

    Hope that helps. Feel free to send a support email if you have further questions. Or post back here and I’ll try to answer.

    • This reply was modified 1 year, 8 months ago by  prime. Reason: fixed bad code formatting
    #33105

    gitoffame
    Participant

    I’m simply trying to run a function in a standard .JS script attached to my character’s parent object.
    I’ve created a custom action named Attack.js, and it runs in parallel with the attack animation in the behavior tree.
    My character runs around and animates just fine, but I just can’t seem to execute the function in this attached script properly.

    The custom action’s (flawed) code:

    
    import RAIN.Core;
    import RAIN.Action;
    @RAINAction
    class Attack extends RAIN.Action.RAINAction
    {
    	function newclass()
    	{
    		actionName = "Attack";
    	}
    	function Start(ai:AI):void
    	{
    		this.transform.parent.gameObject.GetComponent(MeleeWeapon_Use).Fire();
            super.Start(ai);
    	}
    	function Execute(ai:AI):ActionResult
    	{
            return ActionResult.SUCCESS;
    	}
       	function Stop(ai:AI):void
    	{
    		this.transform.parent.gameObject.GetComponent(MeleeWeapon_Use).UnFire();
            super.Stop(ai);
    	}
    }
    

    I’m pretty lost. Being not much of a coder and then only being familiar with .js aren’t really helping matters.
    Thanks again for any pointers.

    #33110

    prime
    Keymaster

    You are saying that you can set the behavior tree up to use this script, but that Execute is ever called? Any chance you can send us a sample scene/project?

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.