You are in a room.
You can see a foobazatron.
> press foobazatron
You are in a room.
You can see a foobazatron and a glop.
> look at glop
It is argent
> press foobazatron
You are in a room.
You can see a foobazatron, a glop and a bar.
> look at bar
It is green
> press foobazatron
You are in a room.
You can see a foobazatron, a glop, a bar and a biff.
> look at biff
It is magenta
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<object name="foobazatron">
<inherit name="editor_object" />
<press type="script">
name = ChooseOne(this.names)
create (name)
set (GetObject(name), "look", "It is " + ChooseOne(this.colors))
MoveObjectHere (GetObject(name))
ShowRoomDescription
</press>
<names type="stringlist">
<value>foo</value>
<value>baz</value>
<value>bar</value>
<value>biff</value>
<value>buffy</value>
<value>glop</value>
<value>zwert</value>
</names>
<colors type="stringlist">
<value>red</value>
<value>green</value>
<value>blue</value>
<value>magenta</value>
<value>cyan</value>
<value>fuschia</value>
<value>argent</value>
</colors>
<look>It's the foobazatron</look>
</object>
</object>
<verb>
<property>press</property>
<pattern>press</pattern>
<defaultexpression>"You can't press " + object.article + "."</defaultexpression>
</verb>
<function name="ChooseOne" parameters="ss" type="string">
return (StringListItem(ss, GetRandomInt(0, ListCount(ss) - 1)))
</function>
<press type="script">
newobject = Clone (originalobject)
newobject.look = "It is " + ChooseOne(this.colors)
newobject.alias = ChooseOne(this.names)
newobject.parent = this.parent
ShowRoomDescription
</press>TFG wrote:Thank you George and The Pixie! Your combined code is exactly what I needed. However, it was giving me some errors, so I switched 'name' to 'alias'.
What if I wanted to make scripts that affected these new clones?
result = null
foreach (o, AllObjects ()) {
if (HasString (o, "alias") {
if (o.alias = nametosearchfor) {
result = o
}
}
}If that made no sense, imagine if I wanted to simply hyperlink one of the cloned objects in the text processor. Normally, I'd just put {object:example}, but is there any way to do that for a clone without assuming that example1 to whatever indeterminate number was present? I mean, what if I create so many clones that it exceeds the premeditated amount of clones that I wanted, how would I be able to do that for them? Certainly there must be a way.
<turnscript name="health cap">
<enabled />
<script><![CDATA[
if (object.health < 0) {
object.health = 0
}
]]></script>
</turnscript>I sort of understand the last bit. But when you put the 'ObjectLink (example)', do you have to put like (example1) or (example2) to specify? If not, how are you specifying which clone to work with? You guys are blowing my mind with some of this code being able to refer to objects without having to manually specify their names, like with the 'newobject' and 'this'.
foreach (obj, ScopeVisibleNotHeld ()) {
msg ("You can see " + ObjectLink (obj))
}
Speaking of which, 'this' still confuses me. You mentioned before that it works because the script belongs to the object. When I usually make scripts, I generally use them in rooms or commands. I get that I could probably just make a verb and just use 'this', so it can work for any object. However, how could I use a command to access that, or could I even use a command to access a verb? I make everything in text adventure mode but I prefer making it kind of like a gamebook in the sense that I just hyperlink commands for everything and hide the command bar. So how can I just hyperlink it and throw it up as something to click?
msg ("You can see " + ObjectLink (object))What confuses me about how to really implement all this into the game I am making is really just how to refer to the objects. For example, if I want to use the if script for when an object's integer was to exceed a certain number, usually I'd just make it as a turn script and put the code as:
<turnscript name="health cap">
<enabled />
<script><![CDATA[
foreach (object, AllObjects ()) {
if (GetBoolean (object, "isnpc")) {
if (object.health < 0) {
object.health = 0
}
}
}
]]></script>
</turnscript>And another thing, if I make it so that this script works for the original object, does it apply also to all of that object's clones?
<function name="Search" parameters="name" type="object">
result = null
foreach (o, AllObjects ()) {
if (HasString (o, "alias") {
if (o.alias = nametosearchfor) {
result = o
}
}
}
return (result)
</function>
TFG wrote:
Regarding George's code, I really like how he made a function. I've never used functions before, so looking at it I have no idea how it works. The 'ss' part and then the return value line 'StringListItem(ss, GetRandomInt(0, ListCount(ss) - 1))'. Can you explain to me how this works, what it means, and how I can use functions like this for other stuff? I understand the GetRandomInt part, but I especially don't understand what ListttCount(ss) - 1) means. Really, I don't understand what anything but the GetRandomInt part means, lol.
<function name="ChooseOne" parameters="ss" type="string">
return (StringListItem(ss, GetRandomInt(0, ListCount(ss) - 1)))
</function>
return (StringListItem(ss, GetRandomInt(0, ListCount(ss) - 1)))