OSP Beginner Example #2641
kugesan1105
started this conversation in
Ideas
Replies: 1 comment
-
import from random {randint}
node Landmark {
has name: str;
can react with Tourist entry {
print("📸 Tourist visits", self.name);
visit [-->];
}
}
node Cafe {
can react with Tourist entry {
if randint(0,1) == 0 {
print("☕ Tourist gets coffee and continues exploring.");
visit [-->];
} else {
print("😴 Tourist got too cozy at Cafe and ended the trip.");
disengage;
}
}
}
node Local {
can react with Tourist entry {
print("👋 Local greets the Tourist");
}
}
walker Tourist {
has visited: list = [];
can start_trip with `root entry {
print("🚶 Tourist begins the journey at", here);
visit [-->];
}
can log_visit with Landmark exit {
self.visited.append(here.name);
}
can end_trip with exit {
print("🏁 Tourist trip ended. Places seen:", self.visited);
}
}
with entry {
# Build world
root ++> Local();
root ++> Landmark(name="Eiffel Tower");
root ++> Cafe();
root ++> Landmark(name="Colosseum");
# Send Tourist walking
a = (root spawn Tourist());
print("Tourist entity ID:", a.visited);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions