Prompts (cliff notes) - using the official Prompts Package

Prompts (cliff notes) - using the official Prompts Package

Install

Prompts Package

  • search for prompts
  • check Crayta Packages
  • click Install
Prompts Package

Configure

User template

  • drag and drop User Prompts View template onto User template
  • (optional) rename to PromptsView or Prompts
User Template

Overview

  • prompts provides a default view in lower right hand corner of display
  • Press {button} to {action}
    • {button} - see list of "Button Options"
    • {action} - script defined
Template View

Button Options

Table of default button options in crayta

buttonOptions = {"forward", "backward", "left", "right", "jump", "sprint", "crouch",
                "interact", "previous", "next", "primary", "secondary", 
                "extra1", "extra2", "extra3", "extra4", "extra5"}

Script examples

Prompts supports two functions:

  • GetButtonPrompts(prompts)
  • GetInteractPrompt(promts)

GetButtonPrompts

Used with:

  • LocalOnButtonPressed
  • ocalOnButtonReleased
  • OnButtonPressed
  • OnButtonReleased

Example

  • default and options (using a table)
  • text in two formats using optional {name}
    • {interact-icon} Equip {name}
    • Stow {name}
  • prompts.<buttonname> can be hard coded i.e. prompts.sprint
  • promptsScript will display based on the "text" property
    • if no icon is specified, the default will be displayed
    • if icon is speccifed, the text will appear unchanged

gist / modded from equipScript

{ name = "equipButton", type = "string", default = "interact" },
{ name = "stowButton", type = "string", options = buttonOptions },
{ name = "equipPrompt", type = "text", tooltip = "{interact-icon} Equip {name}", },
{ name = "stowPrompt", type = "text", tooltip = "", },
  • not needed for prompts to appear
  • butons do nothing unless coded to do something
function EquipScript:LocalOnButtonPressed(buttonName)
	if buttonName == self.properties.equipButton then 
		-- <do some code here>
	end
	
	if buttonName == self.properties.stowButton then 
		-- <do some code here>
	end
end

function EquipScript:GetButtonPrompts(prompts)
	if self.properties.isEquipped then
		prompts[self.properties.stowButton] = 
		self.properties.stowPrompt:
            Format({name = self:GetEntity():FindScriptProperty("friendlyName")})
	else
		prompts[self.properties.equipButton] = 
		self.properties.equipPrompt:
            Format({name = self:GetEntity():FindScriptProperty("friendlyName")})
	end
end
no icon specified icon specified

GetInteractPrompt

Used with OnInteract

Example

  • from Shop Package
  • no -icon specified
  • optional {name} used
  • prompts.interact hard coded

shopScript

ShopScript.Properties = {
	{ name = "shopName", type = "text", },
	{ name = "allowSell", type = "boolean", default = true, },
	{ name = "promptMsg", type = "text", },
}

function ShopScript:OnInteract(player)
	player.shopViewScript:DisplayShop(self.properties.shopName,
        self:GetEntity():FindAllScripts("shopBuyItemScript"), 
        self:GetEntity():FindAllScripts("shopPageScript"), 
        self.properties.allowSell)
end

-- Helper for the Prompts package
function ShopScript:GetInteractPrompt(prompts)
	prompts.interact = self.properties.promptMsg:
        Format({shopName = self.properties.shopName})
end
shopScript interact prompt
1 Like