HeroEngine Forums

HeroEngine Support => Scripting & Programming => Topic started by: Amarak on Jul 20, 14, 12:20:01 AM

Title: Props and Glomming
Post by: Amarak on Jul 20, 14, 12:20:01 AM
Hi guys! I am working on making an object with scripts attached, and so far I haven't found exactly how to do this. There is the My First HSL Script tutorial which is close, but it uses MNAC and is non persistent.

 I started trying to use the Props system which I think would work, but I'm not sure how to add my custom classes to the object, which I want to place in the asset library. I don't know how to add my own Decorators along with the default Props Decorators. I saw something about it:

Code: [Select]
shared function OnInstantiationFromSpec( specDerivedObject as NodeRef )
  if not ( specDerivedObject is kindof _VisibleProp )
    GlomClass( "_VisibleProp", specDerivedObject )
  .
  where specDerivedObject is kindof _VisibleProp
    where specDerivedObject is kindof _Prop
      spec as NodeRef of Class _PropSpec = specDerivedObject.GetMySpec()
      where spec is kindof _PropVisualizationDecorator
        specDerivedObject._PropLoD = spec._PropLoD
      .
    .
  .

I believe this is the proper method but which script would I put it in and how would I attach that script to the object?

 To clarify, I am working on making a crafting station where a player can click on it and it will bring up a GUI for making new items. I believe I can GLOM the class onto the object in the Library Commands but I'm not sure about that.

I've also considered Prototypes, but not sure if that would be the correct route. Any suggestions would be greatly appreciated. I've fond this system a lot more convoluted than Unity where you just drag and drop scripts onto objects.  ;)
Title: Re: Props and Glomming
Post by: Thazager on Jul 20, 14, 12:33:52 AM
While I have not yet used the spec system to make a clickable object, I have had GUIs pop up when the character is near enough to reach the object. This might be one way of doing it. The player could click on Use workstation GUI, to start the crafting. This way uses the triggers to check if the player is near enough and inside the trigger area.

The other way, needs to also check if the player is near enough to reach the object to click it. As I have seen with the monkeytoks, they can be clicked similar to clicking an object, except they can be at any distance which is kind of a problem.  Perhaps the answer is somewhere in between with a combination of the 2 methods.

If the object is a 3D object that the character can carry, you will want more then just GUIs to represent it.
Title: Re: Props and Glomming
Post by: WorldWideZ on Jul 20, 14, 12:49:15 AM
Short hack method to make object clickable , place a asset in game , then use the get node under mouse routine when the player clicks to interrogate what the player is clicking on. use FQN to filter , and then have that launch a GUI window.

Are the crafting stations unique? or are they each the same?

the distance issue can be covered with a vectorlength check , and also can be backed up by a serverside check when the craft request is made
Title: Re: Props and Glomming
Post by: Amarak on Jul 21, 14, 02:53:13 PM
Thanks for the suggestions. I've been experimenting and while I can /mnac a script onto an object to make it clickable, I am not sure how to make the node persistent, and more importantly, how to add it to the Asset Library. I tried the GLOMming method in the Asset Library commands but it doesn't seem to GLOM the class onto my instantiated objects.

For example, you should be able (in the Asset Library) to use the command:
 /HEGLOM LIBRARY $GUIDS OPERATIONS 1: myClass
to GLOM a class onto the object as it's instantiated but mine isn't working that way. It just loads my object and not the script/class. Any ideas on that?
Title: Re: Props and Glomming
Post by: Thazager on Jul 21, 14, 07:14:53 PM
I have only glommed classes onto others through code. I have not done it in command line. I believe glomming needs to be done each time the object is used, which would mean if its done only 1 time in command line it wont be persistent or done each time its used.
Title: Re: Props and Glomming
Post by: Amarak on Jul 21, 14, 11:34:52 PM
I'm using the command system in the Asset Library to glom the class onto an object at instantiation. It just doesn't seem to work like the wiki says it should.
Title: Re: Props and Glomming
Post by: WorldWideZ on Jul 21, 14, 11:48:15 PM
if you want persistent stuff start looking at associations and you will want to use edit instances as the play instances are non persistent. I think most people use glomclass() to achieve glomming , and normally check to see if the glom exists and then create if not. This can be done when you click , if its not a clickable item and needs to be perform glom , if it already is then the fields are there already

what wiki page are you looking at?
Title: Re: Props and Glomming
Post by: Amarak on Jul 22, 14, 01:17:28 AM
I'm following this page http://hewiki.heroengine.com/wiki//HEGLOM#.2FHEGLOM_Command
Halfway down the page is an example of how to use GLOMming with the Asset Library, mine just doesn't seem to work as expected.
Title: Re: Props and Glomming
Post by: WorldWideZ on Jul 22, 14, 01:39:00 AM
personally i might look at making my own /command that ran my own code as a test. have you traced back the code and understand what it does?
Title: Re: Props and Glomming
Post by: Amarak on Jul 22, 14, 01:29:56 PM
I pretty much understand the concepts. I'm wondering if I have to create a prototype for this to work in the Asset Library, since it is an object with a script attached.
Title: Re: Props and Glomming
Post by: WorldWideZ on Jul 22, 14, 05:05:50 PM
While i still think there are better ways to achieve what you want than doing this , lets go through this logically.

have you carried out all steps from the word exercise down? if so what errors did you get ? make sure you clear all the error / chat / console windows before trying to execute the instantiation so new errors can show up.

 
Title: Re: Props and Glomming
Post by: Amarak on Jul 22, 14, 11:44:06 PM
I was learning C# and Java, but am still fairly new to programming so I am trying to keep it simple by following the wiki for now. I am open to suggestions for better ways to do things but for World Builders I really need to have assets created in the Asset Library so they can be added to the world as needed with a simple click. :)

I have the http://hewiki.heroengine.com/wiki/$GLOM tutorial working, where it says it is glomming scripts onto the objects so that is good. The other thing I am trying to do is use the same concept to glom the script from http://hewiki.heroengine.com/wiki/Your_First_HSL_Script that moves an object on mouseover, and add it to the Asset Library. The problem is when I instantiate the object from the Library, I get this error:
Invalid class(TutorialTest1) specified, the library command for this object is improperly constructed.

I am using the command exactly as it says, so there must be something wrong with the script even though it works using the /MNAC method.

If you know of an easier way to attach scripts to objects I'd love to learn! Just remember I am totally new to HSL so what may seem basic stuff to you is still confusing to me.
Title: Re: Props and Glomming
Post by: WorldWideZ on Jul 23, 14, 02:16:46 AM
is the created asset marked mouse targetable ? have you got a println t the beginning of the shared mouse capture function to inform you of  mouse events? might spam you a bit but you will at least know its triggering a event
Title: Re: Props and Glomming
Post by: Amarak on Jul 23, 14, 02:23:05 AM
I modified my previous reply, I am indeed getting an error. Still getting used to Heroblade, I was looking at the Console, but the Error message is in the Chat window. The error is:
Invalid class(TutorialTest1) specified, the library command for this object is improperly constructed.

I find that strange since I am using it according to the wiki.
Title: Re: Props and Glomming
Post by: WorldWideZ on Jul 23, 14, 02:47:36 AM
that says to me that that class is not in your DOM , check its there. remembering of course that this command takes place on the server not the client so the class probably needs to be there as well as on the client
Title: Re: Props and Glomming
Post by: Amarak on Jul 23, 14, 11:15:19 AM
It is a client script, so that could be the problem. I was wondering if, when you GLOM a class onto an object, does it GLOM both client and server side scripts?

You said before "if its not a clickable item and needs to be perform glom , if it already is then the fields are there already".  Doesn't this mean the object still needs a script attached to it?


Also, you said:
Short hack method to make object clickable , place a asset in game , then use the get node under mouse routine when the player clicks to interrogate what the player is clicking on. use FQN to filter , and then have that launch a GUI window.

This is where I don't follow: using the get node under mouse, wouldn't that be in a script, and where would that script be if not attached to an object?
Title: Re: Props and Glomming
Post by: WorldWideZ on Jul 23, 14, 01:15:32 PM
i think under input_mouse , basically you want to listen for mouse events , when you receive one check to see if its a HBNode if it is get the FQN and compare it against the FQN of the model you are expecting a event for, if it is launch a gui window or some other action.

I think gloms might automatically propagate from the server , but i might be wrong. We tend to use inheritance over gloms. i would also look into the event system nature of hero engine, its very handy :D



Title: Re: Props and Glomming
Post by: Amarak on Jul 24, 14, 12:15:23 PM
I've been searching and I haven't found even where to start on the input_mouse concept. Are you saying that there will be a frame by frame check to see what object the mouse is over and if it is an HBNode of a specific FQN (for example rock.hgm) then it will fire a script (for example, to make the object hightlight)?
Title: Re: Props and Glomming
Post by: WorldWideZ on Jul 24, 14, 02:17:30 PM
the method you talked about using before in http://hewiki.heroengine.com/wiki/Your_First_HSL_Script is per frame. in fact its doing exactly what you described.
Title: Re: Props and Glomming
Post by: Amarak on Jul 24, 14, 03:37:55 PM
Ok, and that's where I have the problem. It's a client side script so it isn't persistent, which brings me back to my original question, how do I make it persistent when I use that method? :)
Title: Re: Props and Glomming
Post by: Thazager on Jul 24, 14, 07:02:26 PM
There are a few ways to make objects persistent. One way is by loading the data each time, and then pulling specific data to change the object into the way it should be by storing that data in a  system area. (http://hewiki.heroengine.com/wiki/System_area) An example would be making a cube, and then getting the data to set the size, color, position, rotation, and other things from the system area. When making such an area, after setting up the area and data, the world needs to sleep (reset), them upon waking it will be persistent. Using this way, you can also add a script call to set it.

Another way is making the object in max or maya and then adding that object to the edit instance of that area.
Title: Re: Props and Glomming
Post by: Amarak on Jul 25, 14, 12:23:24 AM
Thanks Thazager! Do you know how I can set it up so the mouse will detect when it is over an object and fire a script when I click on the object, similar to how the mouse works on a gui? This would be client side and would probably solve most of my problems if I could figure out how to make the mouse always be checking for objects in the world. It would have the added bonus of making the client do the checking which would reduce stress on the server.

My main problem is I can do a lot of the scripting, I just don't know how to make those scripts respond to anything when the client loads. In Unity game engine it was a simple matter of drag the script onto an object and it just works. That is a single player system, and HE is Server and Client which is new to me. :)
Title: Re: Props and Glomming
Post by: Amarak on Jul 25, 14, 03:00:51 AM
WorldWideZ said this:
Short hack method to make object clickable , place a asset in game , then use the get node under mouse routine when the player clicks to interrogate what the player is clicking on. use FQN to filter , and then have that launch a GUI window.

This  is exactly what I am trying to figure out. The problem is how do I set up the whole "get node under mouse" to work on 3d objects instead of GUI's?
Title: Re: Props and Glomming
Post by: Thazager on Jul 25, 14, 03:32:36 AM
There is a tutorial on setting up something like for when a player clicks on objects in the world. The Physics node (http://hewiki.heroengine.com/wiki/Physics_node) sets some of the parameters, while this Physics minigame (http://hewiki.heroengine.com/wiki/Physics_mini-game_tutorial) demonstrates it.
Title: Re: Props and Glomming
Post by: Amarak on Jul 25, 14, 01:11:42 PM
Thank you for the reference. While the Physics will come in handy later, it still doesn't help me with the actual mouse to target/select an object to fire a script. I know it has to be something easy, I just can't seem to locate it. I'll look around player controls, the Monkeytok is one thing that can be clicked on but it is a /henpc node.