Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

Script Documentation

Piotr Krupa edited this page Jul 20, 2018 · 30 revisions
+-----------------------------+
| Legend:		      |
|			      |
| "Methods" example:	      |
| obj:myMethod()	      |
|			      |
| "Dot methods" example:      |
| World.myDotMethod()	      |
|			      |
| "Vars" example:	      |
| Input.myVar		      |
|		     	      |
+-----------------------------+
[ Input ]

Vars:
	Keyboard:
		> Key_A, Key_B ...
			A-Z, Num0-Num9, Escape, LControl, LShift, LAlt, LSystem, RControl, RShift, RAlt, RSystem, Menu, 
                        LBracket, RBracket, SemiColon, Comma, Period, Quote, Slash, BackSlash, Tilde, Equal, Dash, Space, 
                        Return, BackSpace, Tab, PageUp, PageDown, End, Home, Insert, Delete, Add, Subtract, Multiply, 
                        Divide, Left, Right, Up, Down, Numpad0-Numpad9, F1-F15, Pause
	Mouse:
		// Empty

Dot methods:
	// When specific key on keyboard is kept | [_U] -> [_U]
	> bool isKept(Key)

	// When specific key on keyboard is pressed | [__] -> [_U]
	> bool isPressed(Key)

	// When specific key on keyboard is unkept | [__] -> [__]
	> bool isUnkept(Key)
	
	// When specific key on keyboard is released | [_U] -> [__]
	> bool isReleased(Key)
[ Script ]

Dot methods:
	> void runScript(string scriptPath)
[ World ]

Dot methods:
	// Get current scene
	> Scene& getScene() 

	// Get scene by name
	> Scene& getScene(string sceneName)

	// Set current scene
	> void setCurrentScene(Scene&) 

	// Set current scene by name
	> void setCurrentScene(string sceneName) 

	// Set current scene
        // @fadeTime in sec
	> void fadeIntoScene(Scene&, float fadeTime)

	// Set current scene by name
        // @fadeTime in sec
	> void fadeIntoScene(string sceneName, float fadeTime) 

	// Get holder to manage textures
	> &TextureDataHolder getTextureDataHolder()
[ World : TextureDataHolder ]

Methods:
	// Get data with texture loaded from specific path 
	// If [reload == true] system will reload texture 
	// even if it has been loaded before.
	// It texture isn't loaded system will load it autmatically
	> TextureData& getData(string texturePath, bool reload)
[ World : Scene ]

Methods:
	// Get entity from this scene by name
	> Entity& getEntity(name)

	// Add entity to this scene to specific group (e.g. "path") 
	> Entity& addEntity(group, name)

	// Clone entity with specific name
	> Entity& cloneEntity(name)

	// Clone specific entity 
	> Entity& cloneEntity(Entity)

	// Remove entity from scene by name
	> bool removeEntity(name)

	// Remove specific entity from scene
	> bool removeEntity(Entity)
[ World : Entity ]

Methods:
	// Get entity name
	string getName()

	// Set entity name
	void setName(string newName)

	// Get scene where entity is
	Scene& getScene()

        // Remove entity in next frame
        void destroy()

	// Creating variables
	// e.g.
	local e = World.getScene():getEntity("myEntity")
	e.myVar = 10
	e.myPi = 3.14159
	e.hello = "Hello world"
	e.ImArray = {1,2,3.5, "string"}
	e.referere = e
	e.anyFunc = function hi(value) print(value) end
[ World : Components ]

Armature
    Methods:
	> void play(string animationName, int playTimes)
	> void fadeIn(string animationName, float fadeInTime, int playTimes)
	// @waitToEnd - wait to end current animation then play
	> void playOnce(string animationName, float fadeInTime, bool waitToEnd, float animationSpeed = 1.f)

	> void setFlipX(bool)
	> bool getFlipX()
	> void setSpeed(float)
	> bool isPlaying()
	> string getCurrentPlayingAnim()

	// @excludes (optional) - list of slot names that do not need to be replace
	// example: replaceSkin("Cedmin", "Face", "Sword", "Armor")
	> void replaceSkin(string armatureName, string... excludes)
	> void setSlotDisplayIndex(string slotName, int displayIndex)
	> void setSlotDisplay(string slotName, string displayName)
	> void setSlotVisibility(string slotName, bool visible)

	> Entity& getEntity()

    Entity methods:
	> Armature& armature()
	> Armature& addArmatureComponent()
- - - - - - - - - - - - - - - - - - - - - - - - -
Base	
    Entity methods:
	> void move(Vec3 delta)
	> void setPosition(Vec3)
	> Vec3 getPosition()

	> void rotate(Vec3 delta)
	> void setRotation(Vec3)
	> Vec3 getRotation()

	> void scale(Vec3 delta)
	> void setScale(Vec3)
	> Vec3 getScale()

	> void setOrigin(Vec2)
	> Vec2 getOrigin()

	> void setVisible(bool)
	> bool isVisible()

- - - - - - - - - - - - - - - - - - - - - - - - -
Camera
    Methods:
        > void setVelocity(float)
        > float getVelocity()

        > void setSmoothness(float)
        > float getSmoothness()

        > void setLock(bool)
        > bool getLock()

        > void stickToPlayer()
        > void stickTo(Entity*)
        > void stickTo(float x)
	> Entity& getEntity()

    Entity methods:
	> Camera& camera()
	> Camera& addCameraComponent()

- - - - - - - - - - - - - - - - - - - - - - - - -
Collider
    Methods:
   	> void move(float x, float y, float z) // move if can

   	> bool isCircleCollider()
   	> void setCircleCollider(bool circleCollider)

   	> void setCircleRadius(float radius)
   	> float getCircleRadius()

   	> void setBoxCollider(bool boxCollider)
   	> bool isBoxCollider()

   	> void setBoxSize(float x, float y)
   	> glm::vec2 getBoxSize()

   	> bool isDynamic()
   	> void setDynamic(bool dynamic) // can be moved by other collider

	> Entity& getEntity()

    Entity methods:
	> Collider& collider()
	> Collider& addColidderComponent()

- - - - - - - - - - - - - - - - - - - - - - - - -
Interactable
    Methods:
        > void setDistance(float distance)
        > float getDistance()

        > void setHeight(float height)
        > float getHeight()

	> Entity& getEntity()

    Entity methods:
	> Interactable& interactable()
	> Interactable& addInteractableComponent()

    Entity callbacks:
	> void onInteraction()

- - - - - - - - - - - - - - - - - - - - - - - - -
Point light
    Methods:
    > glm::vec3 getColor()
    > void setColor(float r, float g, float b)

    > LightPoint::Attenuation getAttenuation()
    > float getAttenuationConstant()
    > float getAttenuationLinear()
    > float getAttenuationQuadratic()
    > void setAttenuation(LightPoint::Attenuation)
    > void setAttenuation(float c, float l, float q)

    > glm::vec3 getAmbientFactor()
    > void setAmbientFactor(float r, float g, float b)

    > glm::vec3 getDiffuseFactor()
    > void setDiffuseFactor(float r, float g, float b)

    > glm::vec3 getSpecularFactor()
    > void setSpecularFactor(float r, float g, float b)

    > Entity& getEntity()

    Entity methods:
    > PointLight& pointLight()
    > PointLight& addPointLightComponent()

- - - - - - - - - - - - - - - - - - - - - - - - -
Scriptable
    Methods:
	> string getFilePath()
	> void runScript(string path)
	> Entity& getEntity()

    Entity methods:
	> Scriptable& scriptable()
	> Scriptable& addScriptableComponent()

    Entity callbacks:
	> onUpdate(float dt)
	> onInit()
	> onChangeScene()

- - - - - - - - - - - - - - - - - - - - - - - - -
Sprite
    Methods:
	> void setTexture(string texturePath)
	> void setTextureData(TextureData&)
	> TextureData& getTextureData()
	> Vec2 getTextureSize()
	> Entity& getEntity()

    Entity methods:
	> Sprite& addSpriteComponent()
	> Sprite& sprite()

- - - - - - - - - - - - - - - - - - - - - - - - -
Animated Sprite:
    Methods:
        > void play()

        > void setLoop(bool loop)
        > bool isLoop()

        > void setFrameNum(int frames)
        > int getFrameNum()

        > void setFrameSize(int width, int height)
        > glm::vec2 getFrameSize()

        > void setRows(int rows)
        > int getRows()

        > void setColumns(int columns)
        > int getColumns()

        > void setSpeed(float speed)
        > float getSpeed()

        > void setTexture(string texturePath)
	> void setTextureData(TextureData&)
	> TextureData& getTextureData()
	> Vec2 getTextureSize()
	> Entity& getEntity()

    Entity methods:
	> SpriAnimatedSprite& addAnimatedSpriteComponent()
	> AnimatedSprite& animatedSprite()

- - - - - - - - - - - - - - - - - - - - - - - - -
Audio
    Methods:
	> SoundBase* get(string name)
	> SoundBase* add(string name)
	> void remove(string name)
	> Entity& getEntity()

    Entity methods:
	> Audio& addAudioComponent()
	> Audio& audio()

- - - - - - - - - - - - - - - - - - - - - - - - -
Trace
    Methods:
	> void play()
	> void stop()
	> void pause()
	> void resume()
	> void setTimeline(int id)
	> Entity& getEntity()

    Entity methods:
	> Trace& addTraceComponent()
	> Trace& trace()

- - - - - - - - - - - - - - - - - - - - - - - - -
Trigger
    Methods:
        /// Type
        // @type: None = 0, ChangeScene = 1, Overlaping = 2
        > void setType(int type)
        > int getType()

        // Change Scene
        > void setScene(std::string scene)
        > std::string getScene()
        > void setEntrance(std::string name)
        > std::string getEntrance()

        /// Shape

        // @shape: Circle = 0, Rectangle = 1
        > void setShapeType(int shape)
        > int getShapeType()

        // Circle
        > void setRadius(float radius)
        > float getRadius() const;

        // Rectangle
        > void setRectSize(float x, float y)
        > glm::vec2 getRectSize()

    Entity methods:
	> Trigger& addTriggerComponent()
	> Trigger& trigger()

    Entity callbacks:
        // Overlaping
	> onEnter()
	> onInside()
	> onLeave()

[ Music ]

Dot methods:
    
    > void play(unsigned int musicTrack, string playlistName)
    > void play(unsigned int musicTrack, string playlistName, string fileName)

    > void pause()
    > void pause(int musicTrack)

    > void stop()
    > void stop(int musicTrack)

    > bool includes(string playlistName, string fileName)

    // PlayingModes:
    //   Random,
    //   Orderly,
    //   Single
    > void setPlayingMode(string playlistName, PlayingMode mode)

    > void setVolume(float volume)
    > void setVolume(float volume, string playlistName)
    > void setVolume(float volume, string playlistName, string fileName)
    > void getVolume(string fileName)

    > RatMusic& get(string fileName)
    > RatMusic* getCurrentPlaying(unsigned int musicTrack)

    > void loadPlaylistFromJson(string fileName)

    > void addPlaylist(string playlistName, string fileName, ...)

    > void addToPlaylist(string playlistName, string fileName, ...)

    > void removeFromPlaylist(string playlistName)
    > void removeFromPlaylist(string playlistName, string fileName)
    
    > Equalizer& getEqualizer(string fileName)
    > Reverb& getReverb(string fileName)
    > Echo& getEcho(string fileName)

    > void cleanEqualizer(string fileName)
    > void cleanReverb(string fileName)
    > void cleanEcho(string fileName)

    > void cleanEffects()
    
    > void setGlobalEffects()

[ Sound]

Dot methods:
    
   > void play()
   > void pause()
   > void stop()

   > void setVolume(float soundVolume)
   > float getVolume()

- - - - - - - - - - - - - - - - - - - - - - - - -
SoundBase

    Methods:

	> void play()
	> void stop()
	> void pause()

        > float getVolume()
        > void setVolume(float volume)

        > float getPitch()
        > void setPitch(float pitch)

        > bool isRelativeToListener()
        > void setRelativeToListener(bool relative)

        > float getAttenuation()
        > void setAttenuation(float attenuation)

        > float getMinDistance()
        > void setMinDistance(float minDistance)

        > Vec3 getPosition()
        > void setPosition(float x, float y, float z)

        > bool getLoop()
        > void setLoop(bool loop)

        > void setOffset(float beginTime, float endTime)
        > float getLength()
        > float getBeginTime()
        > float getBeginTime()
  
        > Equalizer& getEqualizer()
        > Reverb& getReverb()
        > Echo& getEcho()

        > void cleanEqualizer()
        > void cleanReverb()
        > void cleanEcho()

[ AudioEffects ]

- - - - - - - - - - - - - - - - - - - - - - - - -
Equalizer

    Methods:

    // [Range: 50.0 - 800.0] [Default: 200.0]
    > void lowCutoff(float value)
    
    // [Range: 0.126 - 7.943] [Default: 1.0]
    > void lowGain(float value)


    // [Range: 200.0 - 3000.0] [Default: 500.0]
    > void lowMidCenter(float value)

    // [Range: 0.01 - 1.0] [Default: 1.0]
    > void lowMidWidth(float value)

    // [Range: 0.126 - 7.943] [Default: 1.0]
    > void lowMidGain(float value)


    // [Range: 1000.0 - 8000.0] [Default: 3000.0]
    > void highMidCenter(float value)

    // [Range: 0.01 - 1.0] [Default: 1.0]
    > void highMidWidth(float value)

    // [Range: 0.126 - 7.943] [Default: 1.0]
    > void highMidGain(float value)


    // [Range: 4000.0 - 16000.0] [Default: 6000.0]
    > void highCutoff(float value)

    // [Range: 0.0 - 0.207] [Default: 0.1]
    > void highGain(float value)

- - - - - - - - - - - - - - - - - - - - - - - - -
Reverb

    Methods:


    // [Range: 0.0 - 1.0] [Default: 1.0]
    > void density(float value)

    // [Range: 0.0 - 1.0] [Default: 1.0]
    > void diffusion(float value)

    // [Range: 0.0 - 1.0] [Default: 0.32]
    > void gain(float value)

    // [Range: 0.0 - 1.0] [Default: 0.89]
    > void gainHf(float value)

    // [Range: 0.1 - 20.0] [Default: 1.49]
    > void decayTime(float value)

    // [Range: 0.1 - 2.0] [Default: 0.83]
    > void decayHfRatio(float value)

    // [Range: 0.0 - 3.16] [Default: 0.05]
    > void reflectionsGain(float value) 

    // [Range: 0.0 - 0.3] [Default: 0.007]
    > void reflectionsDelay(float value)

    // [Range: 0.0 - 0.1] [Default: 0.011]
    > void lateReverbDelay(float value)

    // [Range: 0.0 - 10.0] [Default: 1.26]
    > void lateReverbGain(float value)

    // [Range: 0.892 - 1.0] [Default: 0.994]
    > void airAbsorptionGainHf(float value)

    // [Range: 0.0 - 10.0] [Default: 0.0]
    > void roomRolloffFactor(float value)

    // [Default: true]
    > void decayHfLimit(bool value)

- - - - - - - - - - - - - - - - - - - - - - - - -
Echo

    Methods:

    // [Range: 0.0 - 0.207] [Default: 0.1]
    > void delay(float value)

    // [Range: 0.0 - 0.404] [Default: 0.1]
    > void lrDelay(float value)

    // [Range: 0.0 - 0.99] [Default: 0.5]
    > void damping(float value)

    // [Range: 0.0 - 1.0] [Default: 0.5]
    > void feedback(float value)

    // [Range: -1.0 - 1.0] [Default: -1.0]
    > void spread(float value)

- - - - - - - - - - - - - - - - - - - - - - - - -

[ Detail : Clock ]

    // Example of using:
    local clock = Utility.Clock.new()
    clock:restart()
    if clock:elapsed() > 5.00 then print("5 seconds after restart") end

[ Equipment ] 

//There are 2 types of equipment items: 

//1. UsableItem - items that don't have specified slot (like armor or weapon) and can be used. 

//2. WearableItem - items that have specified slot e.g. rings, amulets, armor or weapon. They should always have 2 callbacks //on putting them on and taking them off. 

Methods: 

    // Get UsableItem created in JSON file
    // Warning!!! in case of both Usable and Wearable items you can't use the 
    // same variable twice or more e.g. if you want 
    // to add 2 UsableItems you need to call getUsableItem for each one 
    > UsableItem* getUsableItem(string nameId);

    // Get WearableItem created in JSON file
    > WearableItem* getWearableItem (string nameId);

    // Add UsableItem (returns false if couldn't add to equipment) 
    > bool addUsableItem(UsableItem* item);

    > void addUsableItem(UsableItem* item);

    // return table of all item's nameIds (Wearable and Usable items)
    >sol::table getItemTable()

    //returns number of free slots for UsableItems
    > int getFreeSlotsAmount()

    // change number of available slots for UsableItems (max 20)
    > void resizeSlots(int newCapacity)

    // returns number of available slots for UsableItems
    > int getSlotsAmount()

    // returns status of item replacing (NOT_REPLACED, REPLACED or WAITING)
    > statusOfEq getLastChangeStatus()

    > void closeEquipment()

    > void openEquipment()

    > bool isEquipmentOpen()

    // removes one item with given nameId
    > bool removeItem(string nameId)

    // removes given amount of items
    > bool removeItem(string nameId, int amount)

    // removes specific item
    > bool removeItem(UsableItem* item)

    // removes all items with given nameId
    > bool removeAllItems(string nameId)

    // checks if we have one item with given nameId
    > bool hasItem(string nameId)

    // checks if we have given amount of items
    > bool hasItem(string nameId, int amount)

    // uses item with given nameId if successfull returns true
    > bool useItem(string nameId)

    > bool hasChosenStone(string nameId)

Equipment variables:

    //enum used when we are replacing item
    > StatusOfEq::notReplaced NOT_REPLACED
    > StatusOfEq::replaced REPLACED
    > StatusOfEq::waiting WAITING

UsableItem methods:

    > void setName(string newName)

    > void setDescription(string newDescription)

    > void setIcon(string pathToIcon)

    // called to confirm that item can be used
    > void destroy()

UsableItem methods:

    // method which is called before every use of item if the conditions to using item are met we call destroy()
    > sol::function isUsable

    // callback called when item is used
    >sol::function callback

WearableItem methods:

    > void setName(string newName)

    > void setDescription(string newDescription)

    > void setIcon(string pathToIcon)

WearableItem variables:

    // called when we put item on (e.g. when we are selecting ring)
    > sol::function onActivation

    // called when we take item off (e.g. when we deselect ring)
    > sol::function onDeactivation
Clone this wiki locally