Rex's plugins for Construct2
  • Home
  • Map
  • Tutorial/Templates
  • News
  • About

rex_parse_savedata

Plugin, ACE table, Discussion thread
Dependence:
rex_parse_initialize

Introduction
Save slot on parse.

Usage

Sample capx
Concept
Each user has a dedicate slots set. Each slot has two parts - header and body.
Header
Header is a 1d hash table, i.e. key - value pair, to describe
this slot, all headers of this owner user would be read at the same time to be indexes of these slots.
Body
Body is a 1d hash table, to put main saving data. Read a specific slot body by slot nam
e.

Prepare
Add 
rex_parse_initialize to set api id and javascript key.

Set Owner
Each user has a dedicate slots set. So first step is to set the owner user by "Action:Set owner". The parameter "User ID" might come from authentication.
Save
Follow these steps to save a slot on cloud after set owner done.
  1. Call "Action:Set value" to assign value with key into header or body
  2. Call "Action:Save" to push this slot on cloud by slot name.
  3. "Condition:On save complete" will be triggered if saving completed, otherwise "Condition:On save error" will be triggered.
Load
Follow these steps to load a slot from cloud after set owner.

Get headers
1. Call "Action:Get all headers" to get all headers of this owner user. "Condition:On get headers" will be triggered if get all headers.
2. There are three ways to retrieve header for showing them at UI -
- a. "Condition:For each header", then get each slot name by "Expression:CurSlotName", and get value by "Expression:CurHeaderValue( key )".
Or retrieve each key of a header by "
Condition:For each key" under "Load - header" category, then read key and value by  "Expression:CurKey", and "Expression:CurValue".
- b. get value by "Expression:HeaderValue(  slotName, key )".
- c. get headers JSON string by "Expression:HeadersToJSON", put this string into Yann's JSON plugin.

Get body
3. Call "Action:Get body" with a slot name parameter to get selected slot body. "Condition:On get body complete" will be triggered if get body. "Condition:On get body error" will be triggered if got nothing.
4. After got body completed -
- a. Get body value by "Expression:BodyValue( key )".
Or retrieve each key of a body by "
Condition:For each key" under "Load - body" category, then read key and value by  "Expression:CurKey", and "Expression:CurValue".
- b. Or get body JSON string by "Expression:BodyToJSON".
If there is only a slot, the slot body could be load directly by step 3, 4.
After got headers, there are some conditions could be used to test if a slot is existed.
  • "Condition:Empty" is used to test if there is no slot.
  • "Condition:Is occupied" is used to test if a specific slot had been used.
Clean
Call "
Action:Clean slot" to clean a slot, header and body. Or call "Action:Clean all slots" to clean all slots.
"Condition:On clean complete" will be triggered if clean completed, otherwise "Condition:On clean error" will be triggered.

Last saved time
Last saved time would be stored at key "updatedAt"
( Expression:KeyLastSaveTime ).
User could get the last saved time of a specific header by
Expression:CurHeaderValue( Expression:KeyLastSaveTime ), or get the last saved time of body by
Expression:BodyValue( Expression:KeyLastSaveTime ).
These would return an unixtimestamp, put this value into rex_date to get Year/Month/Date, Hour/Minute/Second.

Write & read permission
Set write permission at "Write permission" in properties table to allow the slots only could be overwrote by all users or only the owner.
Set read permission at "Read permission" in properties table to allow the slots only could be read by all users or only the owner.

Create a free web site with Weebly
  • Home
  • Map
  • Tutorial/Templates
  • News
  • About