wiki.sine.space | sinespace

Difference between revisions of "Scripting/SEconomy"

From wiki.sine.space
Jump to: navigation, search
Line 79: Line 79:
  
  
{{ScriptFunction|void|TransferSilverFrom|(int amount, string reason, int to, Closure onFinished);|Removes 'amount' of silver from player avatar's balance and sends it to 'to' avatar ID. You can also bind a function which will be called when operation is finished (optional), which also returns a Boolean if the operation succeeded or not (for example, API Key limit reached). This method requires AccessKey to be set first.|6=<pre>--the below script will make the object a clickable that gives 10 silver to another avatar
+
{{ScriptFunction|void|TransferSilverFrom|(int amount, string reason, int to, Closure onFinished);|Removes 'amount' of silver from player avatar's balance and sends it to 'to' avatar ID. You can also bind a function which will be called when operation is finished (optional), which also returns a Boolean if the operation succeeded or not (for example, API Key limit reached). This method requires AccessKey to be set first.|5=<pre>--the below script will make the object a clickable that gives 10 silver to another avatar
 
--(Example: Silver transfer)
 
--(Example: Silver transfer)
 
--[The AccessKey we are using below is for preview servers only. Please read the API Keys section above.]
 
--[The AccessKey we are using below is for preview servers only. Please read the API Keys section above.]

Revision as of 05:36, 5 October 2021

API Keys

The SEconomy class gives us the ability to transfer silver or issue silver rewards from Sinespace's vault. Therefore, for the below methods to work, you will need to first set the AcessKey which is an API Key given by Sinespace.

To request an API Key, please open a support ticket including: - A very brief description of what you're doing (game, etc.) - How much you want to give away (I would suggest aim for 2,000-5,000 per day, with each 'activity' generating no more than 500 per 10 minutes on average) - If you need the ability to 'sink' money too (sunken money = higher giveaway limits) - Which account should be responsible for the access key (in the event of teams, this will be the person with management rights over it)


Here's two API Keys which are pre-generated and available to the public:

b9184836-9c73-486a-b058-a0a668b860f7 Maximum 5000 silver per 24 hours per user, AND allows up to 5000 to be deducted as well. Works only on Preview.

11f55b74-69ee-4dd3-8983-17c466912beb Maximum 500 silver per 24 hours per user. Works on Preview or Live.

Note: The above two keys work with DeductSilver() and AddSilver(). You'll need an API Key which has your specific required function enabled.

Members

DeductSilver

void DeductSilver (int amount, Closure onFinished);

Deducts amount of silver from player's silver balance. You can also bind a function which will be called when operation is finished (optional), which also returns a Boolean if the operation succeeded or not (for example, API Key limit reached). This method requires AccessKey to be set first.

--the below script will deduct 50 silver from the person who clicks the object containing it
--(Example: A ticket vendor that requires 50 silver to proceed)
--[The AccessKey we are using below is for preview servers only]

thisGameObject = Space.Host.ExecutingObject

Space.Economy.AccessKey = "b9184836-9c73-486a-b058-a0a668b860f7"


OnPaymentDone = function(success)
  if success then
  Space.Log("You have paid 50 silver. Please proceed.")
  else
  Space.Log("Failed. AccessKey limit may have been reached")
  end
end

OnClick = function()
Space.Economy.DeductSilver(50, OnPaymentDone)

end


thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "Buy ticket (50 silver)"
thisGameObject.Clickable.OnClick(OnClick)



AddSilver

void AddSilver (int amount, Closure onFinished);

Adds amount of silver to player's silver balance. You can also bind a function which will be called when operation is finished (optional), which also returns a Boolean if the operation succeeded or not (for example, API Key limit reached). The source of the silver is Sinespace. This method requires AccessKey to be set first.

--the below script will give every player running it 1 silver every 10 seconds (from SineSpace)
--(Example: A silver giver that encourages visitors to stay)
--[The AccessKey we are using below is for preview servers only]

thisGameObject = Space.Host.ExecutingObject

Space.Economy.AccessKey = "b9184836-9c73-486a-b058-a0a668b860f7"


done = function(success)
  if success then
    Space.Log("1 Silver Recieved")
  end
end

AddSilverCoroutine = function()
  while true do
      Space.Economy.AddSilver(1, done)
      coroutine.yield(10)
  end
end

Space.Host.StartCoroutine(AddSilverCoroutine)



TransferSilverFrom

void TransferSilverFrom (int amount, string reason, int to, Closure onFinished);

Removes 'amount' of silver from player avatar's balance and sends it to 'to' avatar ID. You can also bind a function which will be called when operation is finished (optional), which also returns a Boolean if the operation succeeded or not (for example, API Key limit reached). This method requires AccessKey to be set first.

--the below script will make the object a clickable that gives 10 silver to another avatar
--(Example: Silver transfer)
--[The AccessKey we are using below is for preview servers only. Please read the API Keys section above.]

thisGameObject = Space.Host.ExecutingObject

Space.Economy.AccessKey = "b9184836-9c73-486a-b058-a0a668b860f7"



done = function(success)
    if success then
   Space.Log("10 Silver sent")
 else
   Space.Log("failed")
    end
end
 
OnClick = function()
local avatars=Space.Scene.Avatars
Space.Economy.TransferSilverFrom(10, "testing", avatars[1].ID, done)
end

thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)



IssueReward

void IssueReward (int id, Closure onFinished);

Description


Properties

AccessKey

string AccessKey { set; };

This API Key needs to be set before any of the SEconomy functions will work

 Space.Economy.AccessKey = "b9184836-9c73-486a-b058-a0a668b860f7"