Trying to clone object to the room player is at with expression (SOLVED)
Vitokin
06 Jun 2019, 00:04I tried the following expressions: player.room this.room but nothing works ahah iM a bit lost so i made a spellbook that contains a scroll of light and creates an orb of light, cloning it from my treasures hidden room ((The orb)) I want that orb to show up in same room of the caster player but nothing ;( help please
Vitokin
06 Jun 2019, 00:09player.parent maybe?????

Io
06 Jun 2019, 00:12There's a special block called Clone Object and Move. It Clones the Object and moves the object to Room. In code view:
CloneObjectAndMove (ObjectName, TargetRoomName)
To go to the player's room it's Player.parent.
If you want to keep track of the object later, you can even assign it to a variable!
ThisVariableTracksTheCloneItself = CloneObjectAndMove (ObjectName, TargetRoomName)
Vitokin
06 Jun 2019, 00:14Thank you so much again ;) and i can't believe i got it right for player.parent it means I can actually learn ahah!
hegemonkhan
06 Jun 2019, 04:57(filler for getting my edited post, updated/posted)
the built-in 'parent' Object (reference/pointer) Attribute is what actually controls/determine containment ("folder") heirarchy
(when you see 'parent', think 'location', as this helps with understanding its usage)
player.parent = room
// conceptually: player's location = room
player.parent = room // you're set/moved into the 'room' Room Object
player.parent = room99 // you're set/moved into the 'room99' Room Object
katana.parent = player // the 'katana' Object is set/moved into the default 'player' Player Object (aka, "the inventory")
also, the 'parent' Object (reference/pointer) Attribute, allows for some really cool and powerful applications, for a quick example:
a "follower" code (using the built-in 'parent' Object reference pointer Attribute, and a/my custom 'party_member' Object reference pointer Attribute, within the special 'changedNAME_OF_ATTRIBUTE' Script Attribute):
(the reason I put in my 'party_member' Object reference/pointer Attribute, is to show you that you can use your own-custom Object reference pointer Attributes, which for my example, allows you to set/change its value from 'npc' to 'npc2', which would then cause the 'npc2' to follow the 'player', instead of 'npc' following the 'player'
<object name="room">
<inherit name="editor_room" />
</object>
<object name="room2">
<inherit name="editor_room" />
</object>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<attr name="parent" type="object">room</attr>
<attr name="party_member" type="object">npc</attr>
<attr name="changedparent" type="script">
// player.party_member = npc
// if (not npc.parent = player.parent) {
// if (not npc's location = player's location) {
if (not player.party_member.parent = player.parent) {
player.party_member.parent = player.parent
// player.party_member = npc
// npc.parent = player.parent
// npc's location = player's location
//
// let's pretend we moved the player to 'room2':
// player.parent = room2
//
// npc.parent = room
//
// npc's location (room) is NOT equal to player's location (room2)
// so, we set npc's location to being the same as player's location:
//
// player.party_member.parent = player.parent
//
// player.party_member = npc
// npc.parent = player.parent
// npc's location = player's location (room2)
// player.party_member.parent = player.parent
// player.party_member.parent = room2
//
// npc.parent = room2
// player.parent = room2
}
</attr>
</object>
<object name="npc">
<inherit name="editor_objet" />
<attr name="parent" type="object">room</attr>
</object>
<object name="npc2">
<inherit name="editor_objet" />
<attr name="parent" type="object">room</attr>
</object>
mrangel
06 Jun 2019, 09:46There's even a shorthand function, in case CloneObjectAndMove(some_object, game.pov.parent)
is too much typing for you. You can do CloneObjectAndMoveHere (some_object)
instead, moving the clone to wherever the player is.
Also: When you use player
, it means "the object whose name is player". When you use game.pov
it means "the object the player is currently controlling". A lot of the time, they'll probably be the same. But using game.pov
is a good habit to get into, because it means you're not going to slip and use the wrong one if you ever make a game with multiple playable characters.
Vitokin
06 Jun 2019, 10:13Makes sense thanks mrangel ;) and hegemonkhan!