[Plugin][Behavior] DirectData

Post your work in progress addons and get feedback

Post » Tue Jun 02, 2015 2:55 pm

This Addon is to handle easily with Dictionary and Arrays in every size.
Its based on JSON, so in Construct this Objects are special strings.
You also can use variables with handwritten JSON strings as objects. But dont forget the "".
If you do something wrong, the returned objects can be null(-1) and if debug is on, you recive a message in browser console what happens.

Plugin
Behavior

Access to the runtime persistent Object:

SetPersistObject(path,value):
You can insert Value to specific path, if path not exist it will create.
"myPath,myPath2,...." , "TestValue"
"myPath,myPath2,...." , "{}"
You can also insert complete Dictionary(Json)/Array(Json) to a specific path.
"myPath,myPath2,...." , MyStringObj
You can create paths also as array.
"myPath,myPath2" , "[]"
"myPath,myPath2[],0" , "TestValue"

DelPersistObject(path):
You can del a Value/Dictionary/Array by specific path.
"myPath,delThis"
Del Array is same like Dictionary. NO [] needed in path.

ExistInPersistObject(path):
You can check if path exist.
"myPath,myPath2"
Check Array is same like Dictionary. NO [] needed in path.
returns true/false

GetPersistObject(path):
You can get Value/Dictionary(Json)/Array(Json) from a specific path.
"myPath,myPath2"
Get Array is same like Dictionary. NO [] needed in path.
returns Dictionary(Json)/Array(Json)/Value

ClearPersistObject:
This cleans all values in PersistObject.


Access to the stored Object:

LoadStoredObject:
Load StoredObject from Storage and triggers OnStoredObjectLoaded if finished.

OnStoredObjectLoaded:
The StoredObject is loaded some ticks after "OnStartOfLayout", use this to have a startpoint with loaded StoredObject.

IsStoredObjectLoaded:
To check for example OnTick.
returns true/false

SetStoredObject(path,value):
You can insert Value to specific path, if path not exist it will create.
"myPath,myPath2,...." , "TestValue"
"myPath,myPath2,...." , "{}"
You can also insert complete Dictionary(Json)/Array(Json) to a specific path.
"myPath,myPath2,...." , MyStringObj
You can create paths also as array.
"myPath,myPath2" , "[]"
"myPath,myPath2[],0" , "TestValue"

DelStoredObject(path):
You can del a Value/Dictionary/Array by specific path.
"myPath,delThis"
Del Array is same like Dictionary. NO [] needed in path.

ExistInStoredObject(path):
You can check if path exist.
"myPath,myPath2"
Check Array is same like Dictionary. NO [] needed in path.
returns true/false

GetStoredObject(path):
You can get Value/Dictionary(Json)/Array(Json) from a specific path.
"myPath,myPath2"
Get Array is same like Dictionary. NO [] needed in path.
returns Dictionary(Json)/Array(Json)/Value

ClearStoredObject:
This cleans all values in StoredObject.


Working with a temporary Object:

SetToObject(object,path,value):
You can insert Dictionary(Json)/Array(Json)/Value to specific path, if path not exist it will create, but here you need to input the target Dictionary(Json)/Array(Json).
"{}" , "myPath,myPath2,..." , "TestValue"
myLocalString , "myPath,myPath2,..." , "TestObject" Dictionary must be json, min. {} | []
anyDictionarytring , "myPath,myPath2,..." , myGlobalString
returns the changed Dictionary(Json)/Array(Json).

DelFromObject(object,path):
You can del a Dictionary/Array/Value by specific path of target Dictionary(Json)/Array(Json).
returns the changed Dictionary(Json)/Array(Json).

ExistInObject(object,path):
You can if a specific path exist.
returns true/false

GetFromObject(object,path):
You can get Dictionary(Json)/Array(Json)/Value from a specific path of target Dictionary(Json)/Array(Json).
returns the Dictionary(Json)/Array(Json)/Value.

The Behavior:

Its mostly like the persist object, but it depends on the object.


Other stuff:

ForEach in actions:
ForEach(handler,Dictionary) Value|Dictionary(Json)|Array(Json) in target Dictionary(Json)/Array(Json).
It trigger Foreach in conditions.

ForEach in conditions:
You can filter by ForEachHandler.
Get current Key by ForEachKey.
Get current Value by ForEachValue.

IsNumber(Value):
returns true/false

IsString(Value):
returns true/false

IsDictionary(Value):
returns true/false

IsArray(Value):
returns true/false

IsBoolean(Value):
returns true/false

IsUndefined(Value):
returns true/false

Debug:
It show debug message in browser console.
It view Dictonary/Array as formatet Json.
It is also in construct, but this is with little extensions.


String:

sprintf(string[,var]):
It formats a string with additional vars(max 26).
myvar = funny
sprintf("Hello {0} {1} World.","my",myvar)
->Hello my funny World.


Array:

sort(array)Returns the sorted array.
reverse(array) Returns the reversed array.
push(array) Returns the array with the added element.
getFirst(array) Returns the first element.
getLast(array) Returns the last element.
lastIndexOf(array,value) Search the array for an element and returns its position.
length(array) Returns the number of elements in an array.

All hard to explain for me, but easy and flexible to use, if you understand once.

Examples:

Image

Image

Image

Image

About feedback I would be very happy.

04.06.2015 BugFix: ForEach was working not correctly
10.06.2015 New: sprintf
19.06.2015 New: ExistInObject, ExistInSaveObject
21.06.2015 New: Name changed, StoredObject, value check
22.06.2015 BugFix: Add LoadStoredObject, because autoload dont work correctly anytime. Switched autoload to settings.
24.06.2015 New: Array expressions
12.03.2016 Remove: AutoLoadStorage option
12.03.2016 Add: LogLevel option
12.03.2016 BugFix: Behavior Logging
13.03.2016 Add: Inspector Values
Last edited by deathangel1479 on Thu Oct 19, 2017 1:33 pm, edited 24 times in total.
Sorry for my bad english, but I really do my best! And use and check with Google Translator.
B
10
S
4
G
1
Posts: 158
Reputation: 1,303

Post » Tue Jun 23, 2015 8:41 am

I tried the behavior, so far it's usefull, but it's missing one important feature - get length of the object and forEach to go through the objects.
B
45
S
11
G
4
Posts: 517
Reputation: 7,393

Post » Tue Jun 23, 2015 9:52 am

xoros wrote:I tried the behavior, so far it's usefull, but it's missing one important feature - get length of the object and forEach to go through the objects.


I only builded a dataspace in behavior.
The tools are in the plugin. You think it make sense to have it in behavior, so in every instance?
Sorry for my bad english, but I really do my best! And use and check with Google Translator.
B
10
S
4
G
1
Posts: 158
Reputation: 1,303

Post » Tue Jun 23, 2015 9:56 am

Depends, IMHO behavior is easier to use and more logical, because json objects belongs to the instance and is easily accessible that way.
B
45
S
11
G
4
Posts: 517
Reputation: 7,393

Post » Tue Jun 23, 2015 9:58 am

xoros wrote:Depends, IMHO behavior is easier to use and more logical, because json objects belongs to the instance and is easily accessible that way.


What I mean is the ForEach/Count of the plugin works well for behavior object. They are not needed in behavior itself.

If you have them in behavior, for example you need to pick the correct instance to have a valid foreach (handler,key,value), thats brings all mussy.

They are like system expressions, you also dont have a foreach in every sprite to go through sprites, you have it in system and input the sprite, true?
Sorry for my bad english, but I really do my best! And use and check with Google Translator.
B
10
S
4
G
1
Posts: 158
Reputation: 1,303

Post » Tue Jun 23, 2015 11:25 am

Ah, I see
B
45
S
11
G
4
Posts: 517
Reputation: 7,393

Post » Tue Oct 06, 2015 8:04 pm

Thanks for the awesome tool, I have a bug to report though.
When exporting, with the latest version of construct the runtime crashes because runtime.name can't be used anymore and thus the "project" variable will be null.

Best,
Luca
B
5
S
2
G
1
Posts: 3
Reputation: 653

Post » Fri Mar 11, 2016 12:40 pm

Sorry, I was bussy a long time. Now I have time to go on with my project, so also with the plugins.

Leyart wrote:Thanks for the awesome tool, I have a bug to report though.
When exporting, with the latest version of construct the runtime crashes because runtime.name can't be used anymore and thus the "project" variable will be null.

Best,
Luca


Well, I am not good in javascript.

I updated it. Lost the "autoloadstorage", because many problems.
Sorry for my bad english, but I really do my best! And use and check with Google Translator.
B
10
S
4
G
1
Posts: 158
Reputation: 1,303

Post » Thu Aug 04, 2016 2:15 pm

Can you put a shuffle for the array?
B
14
S
6
G
2
Posts: 81
Reputation: 2,241


Return to Work in Progress Addons

Who is online

Users browsing this forum: No registered users and 0 guests