Velinquish

AI Dungeon Scripting Example

Aug 24th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Checkout the repo examples to get an idea of other ways you can use scripting
  3. // https://github.com/AIDungeon/Scripting/blob/master/examples
  4.  
  5. const modifier = (text) => {
  6.  
  7.   let modifiedText = text
  8.   const lowered = text.toLowerCase()
  9.    
  10.   // The text passed in is either the user's input or players output to modify.
  11.   if(lowered.includes('you become king') || lowered.includes('you are now king')) {    
  12.      
  13.     // You can modify the state variable to keep track of state throughout the adventure
  14.     state.isKing = true
  15.    
  16.     // Setting state.memory.context will cause that to be used instead of the user set memory
  17.     state.memory = {context: 'You are now the king.'}
  18.  
  19.     // You can modify world info entries using the below commands
  20.     // addWorldEntry(keys, entry)
  21.     // removeWorldEntry(index)
  22.     // updateWorldEntry(index, keys, entry)
  23.  
  24.     // You can read world info keys with worldEntries
  25.     const entries = worldEntries
  26.    
  27.     // Setting state.message will set an info message that will be displayed in the game
  28.     // This can be useful for debugging
  29.     state.message = JSON.stringify(entries)
  30.    
  31.     // You can log things to the side console when testing with console.log
  32.     console.log('Player is now king')
  33.    
  34.     modifiedText = text + '\nYou are now the king!'
  35.   }
  36.  
  37.     // You must return an object with the text property defined.
  38.     return {text: modifiedText}
  39. }
  40.  
  41. // Don't modify this part
  42. modifier(text)
  43.  
Add Comment
Please, Sign In to add comment