playMaker

Author Topic: Playmaker Inventory Array Example [SOLVED]  (Read 6469 times)

Kevron

  • Junior Playmaker
  • **
  • Posts: 51
Playmaker Inventory Array Example [SOLVED]
« on: June 13, 2013, 06:52:16 AM »
Hi, I am trying to recreate the array example that does inventory, but I cant find mouse pick event that fires "MOUSE DOWN".

Its a global event, but where does it come from? I guess I am having a brain freeze  moment :)

Edit: Its not a global event.

Cheers,
Tor M
« Last Edit: June 21, 2013, 11:40:50 AM by Kevron »

Flying Robot

  • Sr. Member
  • ****
  • Posts: 293
  • Od ton yebo redro
    • Flying Robot Studios
Re: Playmaker Inventory Array Example
« Reply #1 on: June 13, 2013, 08:19:46 AM »
If you want to use 'MOUSE DOWN' right click a state, add transition, system events. That's where you can find it.

Now, if you've used it once it moves to add transition menu.

Kevron

  • Junior Playmaker
  • **
  • Posts: 51
Re: Playmaker Inventory Array Example
« Reply #2 on: June 13, 2013, 09:00:02 AM »
Thanks, did not know about the system events. Seems like a shortcut to skip "mouse pick event".

Cheers!

Kevron

  • Junior Playmaker
  • **
  • Posts: 51
Re: Playmaker Inventory Array Example
« Reply #3 on: June 13, 2013, 09:18:37 AM »
I am going through the Inventory Array Example, and I am having a hard time understanding how arrays work. I can´t get my brain around "Array list clear", "Hash table keys", "Hash table get".. and so on..

I guess it will be more evident to me what they do when there will be some sort of a "manual" to the different actions, but does anybody know of a good way to understand the concept with arrays?

What I am trying to do it that when my character picks up an object, a "sprite" representation of the object finds the first available slot in the inventory.

So if the character has already picked up two objects, the newly picked up object/sprite will place it self in slot 3.

And if the character uses the sprite that is in slot 2, the sprite in slot 3 will move to the newly available slot. 

And this seems quite close to what the Playmaker inventory array example is about.

I reckon changing from string to texture could solve that I would like to show "sprites" instead of an "label".

I am going to work more with this, but just chime in if you have some tips regarding this example.

Thanks,
Tor M

Flying Robot

  • Sr. Member
  • ****
  • Posts: 293
  • Od ton yebo redro
    • Flying Robot Studios
Re: Playmaker Inventory Array Example
« Reply #4 on: June 13, 2013, 10:03:52 AM »
Thanks, did not know about the system events. Seems like a shortcut to skip "mouse pick event".

Cheers!

mouse pick is kinda different and more versatile. But in places MOUSE DOWN does the job.

The inventory example you are trying is kinda cool. Just remembered that I have to do that system too for one of my project. Let me try something. I'll share it over here.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Playmaker Inventory Array Example
« Reply #5 on: June 14, 2013, 01:51:31 AM »
Hi,

 I am aware of this lack of explanations around what arrays and hashtables are within my system. I need to address this, it's a given for people who programs, and so it's difficult for me to find the right approach to explain this in plain english :)

 basically:

 ArrayList, is simply a "list" of items, so you need to be able to set/get/delete/add/find etc etc, I think that make sense yes?

HashTables are a bit more complex, it's simply a list of Key/value pairs, think of it as a list of properties, you need to reference the property ( the key) and you need the value of this property ( the value), it's like css, "background" is the key and the value could be "#00ff00" which would render the page with a green background.

 here I bring this kind of possibilities within PlayMaker, and for this you need all the various actions to manipulation hashtables.

"clear" simply empties the list
"get" will return the value based on index ( for arrayList, index starts at 0, not 1) or the hashtable key itself
"hashTable Keys" will store all keys in an arrayList, sometimes it's useful if you want to iterate through all keys, NOT to find one, but to process them one way or the other. Typicaly example, you want to create a drop down menu, likely the drop down item name you show to the user is not the actual value you want to refere too. so for this create a hashtable:

"Red": Color(1,0,0)
"Green":Color(0,1,0)
"Blue":Color(0,0,1)

so here in one convenient place you define your drop down content, when you want to display it, you want to get the keys only, and inject them into the ui system of your choice, and for this you only need the keys, so using "hashtable keys" is perfect here.

now, the user picekd one, you want to use that selection to do something, simply use "Hashtable get" and reference what the user picked, say "Blue" and you will get in return Color(0,0,1).

Does that help a bit?

bye,

 Jean

Kevron

  • Junior Playmaker
  • **
  • Posts: 51
Re: Playmaker Inventory Array Example
« Reply #6 on: June 14, 2013, 05:52:29 AM »
Thank you Jean for your explanation, I appreciate you taking the time to lay it out in easier term to those of us that is not so skilled in programming.

I understand the logic behind it, and your explanation is making it clearer.
Thanks!

Tor M

Kevron

  • Junior Playmaker
  • **
  • Posts: 51
Re: Playmaker Inventory Array Example
« Reply #7 on: June 17, 2013, 06:42:29 PM »
I think I am doing some progress here, but I have some questions.

1. How can a share a "scene" with you, if I would like to export a scene for you to dissect? My project is rather large, and I would like just to share/export the necessary files to show what my states are doing.

2. Here is a web player version of the scene I am working on, I guess playing around with it will also show whats not yet in place. https://www.dropbox.com/s/z89e2biw1794vqm/Playmaker_Ngui_ArrayMaker.zip

3. If you "mouse pick" the objects (EarMuff, FireExtinguisher, Gun, Safetyglass), the inventory items does not always come in the order you picked them. This is made with Arraymaker. The setup is nearly identical as the inventory example. Only difference is that instead of showing a GUI label, a string variable is set to select the correct sprite from the NGUI Atlas. So, if you pick the Gun, the Gun sprite is shown. Is it a easy way for the inventory items to appear in the order you picked them?

4. Going into NGUI territory. If you drag an inventory item over one of the cubes, some sort of interaction appears. But every time the user "interact" with the inventory items, they change order? And it is also possible to break the inventory by clicking on them fast with your mouse. Suddenly copies will appear. This is way I would like to share the scene, Its hard to describe what happens in the hierarchy  under runtime.

5. Guess it is still NGUI territory. You can press the mouse button down outside the inventory items, and "drag" and release on the cubes. Then you will get the interaction that should only happen by dragging the inventory items.


Puh.. Sorry for the long list, but I have spent some time on this now. Wondering if its easier to do all the "dragging of inventory items" in Playmaker.

I would appreciate if somebody would like to take a guess on what is happening here. And I would gladly share a project file if somebody could shed some light on the smartest way of doing that.

Thanks,
Tor M 

Kevron

  • Junior Playmaker
  • **
  • Posts: 51
Re: Playmaker Inventory Array Example
« Reply #8 on: June 18, 2013, 08:40:12 AM »
I really enjoy working with Playmaker. As I understand it better and better, a new world is opening in front of my eyes.

I got rid of the NGUI DragDropItem script, and did it with an FSM instead. So NGUI onPress sends an event to FSM to get Mouse X and Mouse Y, and set position every frames. So the object is following the mouse whenever the OnPress = True.

So, point 4 and 5 in the last reply is solved with playmaker.

But I am a man of many questions :)

This is about arrays and game logic:

You pick up a Gun. You can now drag your gun on 10 different objects in scene to get 10 different interactions.

How would you solve this in a clean way? I was thinking about two arrays, one array for inventory items and one array for interactive objects in scene.

So, gun (item) dropped on car (object) would give interaction 2b. And gun (item) dropped on tire (object) would give interaction 4g.

Am I on the right track with this? Is it possible to do this with arrays?

Regards,
Tor Martin

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Playmaker Inventory Array Example
« Reply #9 on: June 19, 2013, 01:29:48 AM »
Hi,

 yep, on the right track, I would use Hashtables for this, and give your items an "id", because if you want to quickly check using "HashTableContainsKey" action.

When I need to bind several properties, I would go this way.

 for your car, maintain a hashtable that reference the interaction type for each weapon,

Car Look up hashtable:
"gun"->2b
"knife"->0

Tire Look up hashtable:
"gun"->2b
"knife"->2b
 

does that make sense? then when the user drop a knife on the tire, you check it against the tire look up hashtable and knows what damage to apply.

Bye,

 Jean


Kevron

  • Junior Playmaker
  • **
  • Posts: 51
Re: Playmaker Inventory Array Example [solved]
« Reply #10 on: June 21, 2013, 11:40:20 AM »
Thank you Jean for your valuable input!
I have now a inventory that works quite good, and should be fairly easy to scale up.

So, I´ll call this thread solved for now.

Have a nice weekend all of you,

Tor M