summaryrefslogtreecommitdiffstats
path: root/scripts/init.rb
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/init.rb')
-rw-r--r--scripts/init.rb59
1 files changed, 53 insertions, 6 deletions
diff --git a/scripts/init.rb b/scripts/init.rb
index 25e8dbc..290598f 100644
--- a/scripts/init.rb
+++ b/scripts/init.rb
@@ -1,19 +1,66 @@
-print "Hello there, this is embedded into TMW!\n"
+print "enter init.rb\n"
class EquipHandler < Tmw::MessageHandler
def initialize()
super
end
- # this isn't possible -- does not override parent receiveMessage
def receiveMessage(computer, message)
+ print "Message ID: ", message.getId(), "\n"
item = message.readLong()
slot = message.readByte()
- print "Trying to equip ", item, " at ", slot, "\n"
+ print "Trying to equip ", item, " at ", slot.to_i(), "\n"
+
+ result = Tmw::MessageOut.new()
+ result.writeShort(Tmw::SMSG_EQUIP_RESPONSE)
+ result.writeByte(Tmw::EQUIP_OK)
+ computer.send(result.getPacket())
+ end
+end
+
+# Override default equip message handler
+Tmw::connectionHandler.registerHandler(Tmw::CMSG_EQUIP, EquipHandler.new())
+
+
+# Remote Ruby expression execution
+class RubyHandler < Tmw::MessageHandler
+ def initialize()
+ super
+ print "Ruby message handler activated\n"
+ end
+
+ def receiveMessage(computer, message)
+ src = message.readString()
+ print src, "\n";
+ # doesn't work properly yet (need to have SWIG use std::string nicely)
+ #eval(src, TOPLEVEL_BINDING)
+ end
+end
+
+Tmw::connectionHandler.registerHandler(0x800, RubyHandler.new())
+
+
+# simple enemy
+class SimpleEnemy < Tmw::Being
+ def initialize()
+ super
+ end
+
+ def update()
+ print "Updating!\n"
end
end
-a = EquipHandler.new()
-Tmw::connectionHandler.registerHandler(Tmw::CMSG_EQUIP, a)
+# simple item
+class SimpleItem < Tmw::Item
+ def initialize()
+ super
+ type = 100
+ end
+
+ def use()
+ print "USE THIS THING!!"
+ end
+end
-print "Done init.rb\n"
+print "exit init.rb\n"