Sample: Soda

From SkyCorp Global
Note - this entity is a modification for The Underworld. Visit the new Mods Portal for more mods, mods on the wiki are no longer maintained. You can put it in-game by visiting the Debug Mod Control Panel in the debug rooms and browse to this mod or copy/paste the JSON below into the program window.

Entity Details

This entity is intended to be used with the Vending Machine sample to demonstrate how an entity can spawn a different entity. However, the entity can also function by itself as a simple demonstration of healing the player.

Author: SkyCorp

Entity JSON Code

{
	"type": "ENTITY",
	"id": "Sample Soda",
	"name":
	{
		"literalString": "Soda"
	},
	"description":
	{
		"literalString": "A can of diet soda."
	},
	"doUse":
	{
		"programBoolean": true
	},
	"isUseable":
	{
		"literalBoolean": true
	},
	"isPickupable":
	{
		"literalBoolean": true
	},
	"luac":  "G0x1YVEAAQQEBAgACgAAAEBzb2RhLmx1YQAAAAAAAAAAAAAAAgIDAAAAJAAAAAcAAAAeAIAAAQAAAAQGAAAAZG9Vc2UAAQAAAAAAAAABAAAAEAAAAAAAAAISAAAABUAAAAaAQAAcgIAABwAAAAXAAAAGAEEAQUABABxAAAEFAAAABoBBAEHAAQAcQAABBQACAAZAQgAcQIAAAgCAAB4AAAEeAIAACgAAAAQHAAAAcGxheWVyAAQHAAAAUGxheWVyAAQMAAAAZ2V0SW5zdGFuY2UABAsAAABNYWluU2NyZWVuAAQMAAAAYWRkR2FtZVRleHQABBoAAABZb3UgZ3VscCBkb3duIHRoZSBzb2RhLiAgAAQFAAAAaGVhbAADAAAAAAAACEAEBQAAAHRoaXMABA0AAABkZWxldGVFbnRpdHkAAAAAABIAAAAHAAAABwAAAAcAAAAHAAAACQAAAAkAAAAJAAAACQAAAAsAAAALAAAACwAAAAsAAAANAAAADQAAAA0AAAAPAAAADwAAABAAAAAAAAAAAAAAAAMAAAAQAAAAAQAAABAAAAAAAAAAAAAAAA=="
}

LUA Source Code

function doUse()
	-- NOTE: The engine actually has support for food objects that will adjust
	-- the player's weight appropriately, however, this is not yet exposed to
	-- LUA modding as of Feb 2018.  For the purposes of this example, the soda
	-- will just replenish HP with no other consequences.

	player = Player.getInstance();

	MainScreen.addGameText('You gulp down the soda.  ');	

	player.heal(3); -- Heal 3HP

	this.deleteEntity(); -- Remove entity from world or inventory

	return true; -- Automatic continue scene
end