{
 "title": "TeleScript Code Examples",
 "slug": "telescript-code-examples",
 "category": "The world",
 "url": "https://x-change.life/wiki/telescript-code-examples/",
 "summary": "Here's some sample code for TeleScriptOS, the operating system on General Magic phones, all written in High TeleScript (the glossary's on the TeleScriptOS page).",
 "tags": [],
 "checked": null,
 "game_version": "0.27.0.9",
 "words": 209,
 "headings": [
  {
   "level": 2,
   "text": "Basics",
   "id": "basics"
  },
  {
   "level": 2,
   "text": "Identity check",
   "id": "identity-check"
  }
 ],
 "links": [
  "TeleScriptOS",
  "General Magic",
  "X-Change Pills"
 ],
 "watches": [],
 "markdown": "Here's some sample code for [[TeleScriptOS]], the operating system on [[General Magic]] phones, all written in High TeleScript (the glossary's on the TeleScriptOS page).\n\nThis agent asks Aphrodite's cloud what's on in the city today, where `getCityEvents` is an operation on a `TeleService` interface, so the service handles the request and the network handshake for you.\n\n```\n// Example of a TeleScriptOS API call to retrieve city event data\nTeleService: interface(AphroditeCloud) = (\n    public\n        getCityEvents: op(date: Date) Collection;\n);\n\nCityEventAgent: class(Agent) = (\n    public\n        retrieveEvents: sponsored op() = {\n            eventCollection = AphroditeCloud@TeleService.getCityEvents(today());\n            foreach (event in eventCollection) {\n                displayEventDetails(event);\n            }\n        };\n);\n```\n\n## Basics\n\nTo make an agent, extend the `Agent` class and write a `live` method.\n\n```\nMyAgent: class(Agent) = (\n    public\n        live: sponsored op() = {\n            // Your code here\n        };\n);\n```\n\nAn interface lists the methods a class must implement.\n\n```\nMyService: interface(Object) = (\n    public\n        performAction: op(argument: DataType);\n);\n```\n\nAgents visit places to do tasks or use resources, and this is what a place looks like.\n\n```\nMyPlace: class(Place) = (\n    public\n        provideService: op(agent: Agent) = {\n            // Service logic here\n        };\n);\n```\n\nAn agent uses `go` to travel to another service in the Magic Cloud.\n\n```\ntravelAgent: sponsored op(destination: Teleaddress) = {\n    *.go(destination);\n    // Perform actions at the destination\n};\n```\n\nTo reach a MagicNet service, use a TeleService interface that matches one of Aphrodite's cloud systems.\n\n```\nMagicNetConnect: interface(MagicCloud) = (\n    public\n        getData: op(query: String) DataResult;\n);\n\ndataAgent: class(Agent) = (\n    public\n        fetchData: sponsored op(query: String) = {\n            result = MagicNetConnect@MagicCloud.getData(query);\n            // Process the fetched data\n        };\n);\n```\n\nAn identity service returns the user's profile.\n\n```\nidentityAgent: class(Agent) = (\n    public\n        getUserProfile: sponsored op(userID: String) UserProfile = {\n            profile = IdentityService@AphroditeCloud.getUserProfile(userID);\n            return profile;\n        };\n);\n```\n\nAn agent sends the user a message through the notification service.\n\n```\nnotifyAgent: class(Agent) = (\n    public\n        sendMessage: sponsored op(userID: String, message: String) = {\n            UserNotificationService@UserDevices.notify(userID, message);\n        };\n);\n```\n\n## Identity check\n\nPeople in Summer City change sex with [[X-Change Pills]], so the city's identity registry holds a male and a female profile for the same DNA, and this agent checks a DNA sample against both.\n\n```\nIdentityAgent: class(Agent) = (\n    public\n        verifyIdentity: sponsored op(dnaSample: DNA) UserIdentity = {\n            userMaleProfile = IdentityService@AphroditeCloud.getProfile(dnaSample, Male);\n            userFemaleProfile = IdentityService@AphroditeCloud.getProfile(dnaSample, Female);\n            if (userMaleProfile.isValid && userFemaleProfile.isValid) {\n                return UserIdentity(userMaleProfile, userFemaleProfile);\n            } else {\n                raise IdentityVerificationException(\"User identity could not be verified.\");\n            }\n        };\n);\n```\n\nThis one signs you up for city events to suit your tastes, so when you change sex it asks which sex you are now and updates your calendar to match.\n\n```\nEventSubscriptionAgent: class(Agent) = (\n    public\n        subscribeToEvents: sponsored op(userPreferences: UserPreferences) = {\n            currentGender = IdentityService@AphroditeCloud.getCurrentGenderIdentity(userPreferences.userID);\n            tailoredEvents = EventFilteringService@CityEvents.getEventsForGender(currentGender, userPreferences);\n            CalendarService@UserDevices.updateUserCalendar(userPreferences.userID, tailoredEvents);\n        };\n);\n```\n",
 "meta": {
  "title": "TeleScript Code Examples",
  "category": "The world",
  "kept_by": "hand",
  "fact": "Summer City phones run code that checks which sex you are today."
 }
}