Mythruna
April 29, 2024, 05:40:06 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome to the new forums. See "Announcements" for a note for new users.
 
   Home   Help Search Login Register  
Pages: 1 2 3 [4] 5
  Print  
Author Topic: Paul, API: Info/Allow Suggestions?  (Read 49672 times)
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #45 on: September 15, 2013, 06:42:37 AM »

Paul, I found your JsonParser class, and I am wondering if you have an javadocs on it, because it's package org.progeeks.json is not located at http://meta-jb.sourceforge.net/javadoc/index.html; I would also like to state files have been quite a weak point for me for quite some time.. should I learn your parser or go back to the basics of files and learn from there first?
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #46 on: September 15, 2013, 11:03:19 AM »

There is a javadoc jar here:
https://sourceforge.net/p/meta-jb/svn/HEAD/tree/trunk/dev/m2-repo/org/meta-jb/meta-jb-json/1.0.1/

I don't know if I actually documented the classes, though.  I don't know that I would attempt this at your current skill level.

...and just for the record, it would be superbad to read/write directly from the player .json files.  That's what PlayerData is for.
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #47 on: September 15, 2013, 11:13:22 AM »

...and just for the record, it would be superbad to read/write directly from the player .json files.  That's what PlayerData is for.
My goal with your json parser and reader/writer was to make my own files with (e.g: myfile.json), not to mess with your current ones. I don't know much about how you implemented it, would you rather I not use your json parser?
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #48 on: September 15, 2013, 11:19:41 AM »

...and just for the record, it would be superbad to read/write directly from the player .json files.  That's what PlayerData is for.
My goal with your json parser and reader/writer was to make my own files with (e.g: myfile.json), not to mess with your current ones. I don't know much about how you implemented it, would you rather I not use your json parser?

My JSON parser is great.  I just foresee a lot of complications for someone still just learning.

What kind of data are you trying to store?
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #49 on: September 15, 2013, 12:45:08 PM »

...and just for the record, it would be superbad to read/write directly from the player .json files.  That's what PlayerData is for.
My goal with your json parser and reader/writer was to make my own files with (e.g: myfile.json), not to mess with your current ones. I don't know much about how you implemented it, would you rather I not use your json parser?

My JSON parser is great.  I just foresee a lot of complications for someone still just learning.

What kind of data are you trying to store?
I am going to store coordinates, and the syntax I was going to look for is this:

Quote
    "<player name>" : {
        "<home name>" : {
            "x" : <pos>.5,
            "y" : <pos>.0,
            "z" : <pos>.5
        },
        "<second home name>" : {
            "x" : <pos>.5,
            "y" : <pos>.0,
            "z" : <pos>.5
        }
    }

I'm not sure if or when I would enable a second home.
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #50 on: September 15, 2013, 02:46:08 PM »

You can also store data right on the player entity and keep it out of separate files.  (Or you could store it in the playerData easily enough, too.)

playerData.setLocation( "myHome", someLocation )

Storing on an entity is harder in Java but it would then be associated with the character instead of the player... which is probably desirable for the use-cases you talk about.  You can do that in the player data also, but it's a bit more complicated because right now the player data only supports one character and this will eventually be deprecated over using entities.

Hmm... looks like with the generic entity variables thing that I only support int so far.

So, you could do:
playerData.setLocation( "characterInfo.home", someLocation );
(note that if you tried to use the actual home name then you run into problems because a) how would you look it up and b) what if the name changes.  You could use the entity ID but things start to get complicated.)
The above will probably break when I support when I support multiple characters per player.

Or if you want to use the entity variable support (that only supports int right now but that may work for you), you could do something like:
Code:
EntityData ed ...
EntityId playerEntityId ...
LocalVariables vars = new LocalVariables(ed, playerEntityId);
vars.setInt( "home.x", x );
vars.setInt( "home.y", y );

...or something.
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #51 on: September 15, 2013, 03:22:12 PM »

I have been trying to figure out how this is null for quite some time, because I am getting fed up about asking you about every last thing.

Vector3f location = pos.getLocation() is null from this set:
Code:
EntityId playerEntity = player.getPlayer();
GameSystems systems = player.getSystems();
EntityData ed = systems.getEntityData();
Position pos = ed.getComponent(playerEntity, Position.class);
Vector3f location = pos.getLocation();
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #52 on: September 15, 2013, 03:53:23 PM »

If you get an NPE  on this line:
Vector3f location = pos.getLocation()

then pos is null.
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #53 on: September 15, 2013, 04:28:45 PM »

I knew at least that much, I always say I am not going to rush, but I always end up doing so. I used to actually write my problems descriptively and neatly on the bukkit forums, I don't know where I went wrong.

I see we have taken the PlayerEvent.getContext() into a "player" variable

EntityId playerEntity = player.getPlayer() for the entity, not null
GameSystems systems = player.getSystems() to get the game systems, not null
EntityData ed = systems.getEntityData() to get the entity(player)'s data, not null
Position pos = ed.getComponent(playerEntity, Position.class) takes two parameters, (EntityID, Class), SHOULDN'T be null ~ but is
Vector3f location = pos.getLocation() gets the three floats for the x,y,z; null because pos is null.

Where did we(you) go wrong..?
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #54 on: September 15, 2013, 04:35:00 PM »

Hmmm... player must not have a position.  I sort of forget the kind of messed up way that players are dealt with differently.

So the real solution is more complicated and will break for sure in the next version.
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #55 on: September 15, 2013, 04:42:07 PM »

Hmmm... player must not have a position.  I sort of forget the kind of messed up way that players are dealt with differently.

So the real solution is more complicated and will break for sure in the next version.
Okay Tongue; and when I said we(you) I was just messing around, so if I made you upset, sorry about that.
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #56 on: September 15, 2013, 06:43:22 PM »

I do have a question involving the API, compared to the 20120627 build API, about how much better/easier would you say the newest API is, and does it still have the same base functionality (like when you register event types with the EventDispatcher)?
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #57 on: September 15, 2013, 08:27:19 PM »

I do have a question involving the API, compared to the 20120627 build API, about how much better/easier would you say the newest API is, and does it still have the same base functionality (like when you register event types with the EventDispatcher)?

So far:
-event dispatcher is exactly the same
-entity-related stuff is exactly the same

...pretty much everything else is changed or will be different.  I have better ways of doing stuff now so I get to clean some things up that were convoluted before.
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #58 on: September 18, 2013, 04:47:16 PM »

Closures..
ScriptedAction action = new ScriptedAction(String group, String name, Closure closure);

I have been having the hardest time with this, all I know are closures in groovy for things like files:
Code:
File file = new File("file.txt")
file.eachLine { line -> //Closure initiated.
    //do stuff.
}

Then the definition for closures (computer science):
Quote
In programming languages, a closure (also lexical closure or function closure) is a function or reference to a function together with a referencing environment—a table storing a reference to each of the non-local variables (also called free variables or upvalues) of that function.[1] A closure—unlike a plain function pointer—allows a function to access those non-local variables even when invoked outside its immediate lexical scope.

Basically, it is a method that is in a way "hidden", I believe, since whenever I put a println within the eachLine function in groovy, it doesn't print out, but yet I still get the information from within the eachLine function.

How would I use the Closure for this type?

****EDIT****

This is my current code, and the interface ActionParameter is a completely empty class..
Code:
public void newEvent(EventType<PlayerEvent> type, PlayerEvent e) {
ActionParameter actionPar = new ActionParameter() {
};

ScriptedAction action = new ScriptedAction("testGroup", "testName", (Closure) actionPar);
action.setType(ActionType.Block);

ActionManager actionManager = new ActionManager();
actionManager.addAction(action);
}
« Last Edit: September 18, 2013, 04:50:51 PM by Shzylo » Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #59 on: September 18, 2013, 05:58:54 PM »

Scripted actions are for scripts.  If you are not using scripting then you would not use a scripted action.
Logged
Pages: 1 2 3 [4] 5
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!