Pick and move
Deckrect
20 Nov 2016, 15:04I have been working on a project where, during character creation, i want the player be able to pick up items for the starting character and, after a certain number of items picked, player will be moved to another room. I would know doing it if placing scripts in the items, but as these will be the game items, i fer it may have weird effects in future.
So, i cannot figure out how allowing player to inspect items in the room and then after picking a limited number, be moved to another room.
My first attempt was using turns, however every inspection of an item counts as a turn, what is not working.
I would, also, instead of counting items, make multiple rooms like this one, allowing the player to pick up just one item before be moved to the next room. However, for this approach, i should know how to code a "If player picks up an item, them move player to room X". And i have no clue about how doing so.
May anyone help me on counting how many items were taken OR identifying if the player did pick an item? Perhaps the second option would be better, because it allows me to clone the same room a few times, so the player may pick up the same type of item (Healing Potion, for example), multiple times.
The Pixie
20 Nov 2016, 16:05Use a turn script in the creation room. Have it count the items in the player inventory, and if greater than a certain amount, move the player.
hegemonkhan
20 Nov 2016, 16:25using Pixie's 'notaturn' (Pixie's 'notaturn' Boolean Attirbute) design/idea, here's a way to control the game 's internal turns:
(the trick is to have your script that increases the turns, be inside of an 'if' Script, thus it will only increase turns when you want it to, via controlling the flag/indicator Attribute used as the condition for/within the 'if' Script)
<game name="example_game">
// state 0 (and down): no game turns are occuring
// state 1 (and up): game turns are occuring
// you can add more states if you want (this: scalability, is why I'm using an Integer Attribute, instead of a Boolean Attribute)
// any state greater than zero, the game turns are occuring
// any state as zero or lesser than zero, the game turns are not occuring
<attr name="state_integer_attribute" type="int">0</attr> // I have it set for initially being 'state 0' for character creation
<attr name="turn_integer_attribute" type="int">0</attr>
<attr name="statusattributes" type="simplestringdictionary">turn_integer_attribute = Turn: !</attr>
</game>
<turnscript name="global_turnscript">
<attr name="enabled" type="boolean">true</attr>
<script>
if (game.state_integer_attribute > 0) {
game.turn_integer_attribute = game.turn_integer_attribute + 1
}
</script>
</turnscript>
<function name="set_state_function" parameters="input_value_parameter">
if (IsInt (input_value_parameter)) {
game.state_integer_attribute = input_value_parameter
} else {
msg ("Error: your argument (literal/direct value or VARIABLE's value) is not an integer (int), so fix up your code")
}
</function>
// here's how to use the 'set_state_function' Function:
// using a literal/direct Integer (int) Value for your argument:
set_state_function (0) // state 0
set_state_function (1) // state 1
set_state_function (2) // state 2
set_state_function (-1) // state -1
// or, using a variable VARIABLE for your argument:
my_variable = 0 // or: 1, 2, -1, etc etc etc
set_state_function (my_variable)
// or, using an Attribute VARIABLE for your argument:
game.my_attribute = 0 // or: 1, 2, -1, etc etc etc
set_state_function (game.my_attribute)
and as for your items:
(I'm using the special 'changedNAME_OF_ATTRIBUTE' Script Attribute)
<game name="example_game">
<attr name="starting_item_count_integer_attribute" type="int">0</attr>
<attr name="changedstarting_item_count_integer_attribute" type="script">
if (starting_item_count_integer_attribute = 5) { // or whatever number/value you want
player.parent = NAME_OF_DESTINATION_ROOM_OBJECT // replace the caps with the name of the room you want to move to
starting_item_count_integer_attribute = 0 // resetting this, for 'just-in-case' handling for whatever your design might be, or I think you can use ' = null ' for removing this Attribute, if you don't need it after moving to the new room, which would be better than resetting it to zero
}
</attr>
</game>
// this is only for your character creation 'starting/initial' items and your item count of these for moving to another room
// (this deisgn isn't the best, but it's done because it hopefully can handle whatever/however you want to use it, I hope)
// if I knew what your design was or could create the design for you, then I'd do something better than this...
<type name="starting_item_type">
<attr name="take" type="boolean">true</attr> // or it's (a Boolean Attribute's) shorthand: <take />
// --------------------------------------------------------------------------------
// here's also an example (pretend Attributes -- you'd add these to your specific Objects, and/or this 'starting_item_type' Object Type or another Object Type) for 'inspecting' your item:
<attr name="inspect" type="script">
set_state_function (0)
ClearScreen
msg ("Name: " + this.alias)
msg ("Type: " + this.equipment_type_string_attribute)
msg ("Damage: " + this.damage_integer_attribute)
msg ("Price: " + this.price_integer_attribute)
wait {
ClearScreen
set_state_function (1)
}
</attr>
// ----------------------------------------------------------------------
<attr name="changedparent" type="script">
if (this.parent = game.pov) {
firsttime {
game.starting_item_count_integer_attribute = game.starting_item_count_integer_attribute + 1
} otherwise {
// leave this blank
}
}
</attr>
</type>
<verb>
<property>inspect</property>
<pattern>inspect</pattern>
<defaultexpression>You can't inspect that!</defaultexpression>
</verb>
// example starting item:
<object name="knife_object">
<inherit name="starting_item_type" />
<attr name="parent" type="object">room</attr>
</object>
<object name="player">
<attr name="parent" type="object">room</attr>
</object>
<object name="room">
</object>
Deckrect
20 Nov 2016, 16:45Hey, HK! I really appreciate the effort and all this explanations. However, it is looking very high level coding for my lack of skills. I will spend some time trying to digest it and see if i am able to implement it, as i am a guy who uses the GUI most of the time.
However, i have been thinking two very simple steps of this process: How may i express and "If player takes anyone item" and "How do i command Quest to check the number of items in inventory".
hegemonkhan
20 Nov 2016, 16:52if you need help with how to do anything in the GUI/Editor, let me know. But try and see if you can understand and follow my post above... might be wise to backup your game file (make a copy), and try to understand and do my code in the GUI/Editor within either your main game file, or your 'copy/testing' game file... so, not to mess up your actual game file (either your main game file or your copy/backup game file).
XanMag
20 Nov 2016, 16:55Can you use a change integer attribute script and add one for every item that is added to the inventory? Then use an 'If' script to check the value of the attribute? If integer equals 5, then move player to 'x room'?
This would force you to manually add a take script that moves objects to the player inventory, but I think it is doable? I'm thinking this is similar to Pixie's suggestion but a little more 'duct taped'... =)
Deckrect
20 Nov 2016, 17:02My main way of doing it would be storing a counter in the room and adding numbers to this counter, using the "On Take" script for every item. However, i fear what would happen to the game with items running around with this script on it! lol
I suppose the most simple way is, for example, having three item selection rooms. In room 1, there is a script to move player as soon it takes any one object. Then, the same happens in rooms 2 and 3. Except perhaps that room 3 sends the player to the game start. It gives me the opportunity of offering the very same items multiple times.
I lied a little bit here, because player will not be selecting Items itself, but other objects. However, for programming, it will be the same, actually.
hegemonkhan
20 Nov 2016, 17:07@ XanMag:
from my code above, here's an example:
// handles moving player to 'room' room when 5 items reached (of course room and value can be changed):
<attr name="changedstarting_item_count_integer_attribute" type="script">
if (starting_item_count_integer_attribute = 5) { // or whatever number/value you want
player.parent = NAME_OF_DESTINATION_ROOM_OBJECT // replace the caps with the name of the room you want to move to
starting_item_count_integer_attribute = 0 // resetting this, for 'just-in-case' handling for whatever your design might be, or I think you can use ' = null ' for removing this Attribute, if you don't need it after moving to the new room, which would be better than resetting it to zero
}
</attr>
// ---------------------
// handles increasing the starting item count, activates upon 'taking' item (and thus the item's parent changes to being that of the 'player' --- assuming we keep it simple --- no storage objects on the player or outside of the player, lol):
<attr name="changedparent" type="script">
if (this.parent = game.pov) {
firsttime {
game.starting_item_count_integer_attribute = game.starting_item_count_integer_attribute + 1
} otherwise {
// leave this blank
}
}
</attr>
hegemonkhan
20 Nov 2016, 17:10@ Derelict:
"My main way of doing it would be storing a counter in the room and adding numbers to this counter, using the "On Take" script for every item. However, i fear what would happen to the game with items running around with this script on it! lol (Derelict)"
simple solution (and your design/method is good for your ability):
use the 'firsttime-otherwise' Script (hopefully you know how to get to this in the GUI/Editor's scripting/add new script options):
http://docs.textadventures.co.uk/quest/scripts/firsttime.html
Deckrect
20 Nov 2016, 17:42HK, you are a genius! I am already trying the "On First time" script, and i am having a few issues by now. However, it sounds very promising and elegant. I guess i will find a way to solve the issues.
hegemonkhan
20 Nov 2016, 17:46if you need any help with using the 'firstime-otherwise / On First time' Script, let me know, and I'll try to help you out.
if it's not obvious... it is how you force/have something to only be done once, and then afterwards/next time(s), the 'otherwise' Script is run
(behind the scene, it's just doing the 'if' scripting check of whatever type of Attribute it creates/uses, for you)
Deckrect
20 Nov 2016, 17:52Yes, yes... I am doing this:
firsttime {
IncreaseObjectCounter (Free Cards, ""Selection"")
AddToInventory (Academics Card)
}
otherwise {
AddToInventory (Academics Card)
}
It is returning some errors. The first one i must solve is that i believe it is not recognizing the "Selection" counter. Perhaps i should use a "set counter" first?
hegemonkhan
20 Nov 2016, 17:53you have ""Selection"", it should be: "Selection"
assuming, you should have already added/created your 'Selection' Integer Attribute (with initial Value of 0) to your 'Free Cards' Object, so no need to use the 'set counter', as this does the same thing.
The Pixie
20 Nov 2016, 17:54However, i have been thinking two very simple steps of this process: How may i express and "If player takes anyone item" and "How do i command Quest to check the number of items in inventory".
That is the choice. You need the script to get triggered, either when the player takes something or every turn. I think the latter is easy, with a turn script, and if the turn script is in the room, it will automatically stop when the room is left.
My main way of doing it would be storing a counter in the room and adding numbers to this counter, using the "On Take" script for every item. However, i fear what would happen to the game with items running around with this script on it! lol
They will keep adding to the counter when the item gets taken again. If you never look at the counter again, no problem. But remember you need to allow for the player taking an item, and then changing her mind, and dropping it in the creation room. This is why I think counting the items in the inventory is a better approach:
if (ListCount(ScopeInventory()) > 5) {
MoveObject (player, next_room)
}
You could do that in every take script or in a turn script - or the script where you clone objects if you are doing it that way.
Deckrect
20 Nov 2016, 18:11Ok. It worked, but at a cost. I could manage to avoid doing multiple rooms for selection by using the counter, however, once again, i have this weird script running on the Object, so every time in future the player picks the same Object, it will be moved back to the beginning of the game.
On the previous character creation steps, the player was able to select "Archetypes", which added a set of cards to the inventory. The current step i was working on was the Free Cards step, to pick up a number of cards not linked to a package.
I guess i will create an Object, that simply clones the desired card and adds the counter. It will work better and i will not remain stuck here.
hegemonkhan
20 Nov 2016, 18:17just for some quick GUI/Editor to in-code, if interested:
GUI/Editor:
IncreaseObjectCounter (Free Cards, "Selection")
is the same as, in-code:
Free Cards.Selection = Free Cards.Selection + 1
while the GUI/Editor's 'IncreaseObjectCounter(xxx)' is limited to only '+ 1', that's not the case for/with directly in-code (and also not the case if you use the GUI/Editor's scripting's '[EXPRESSION]' option, it allows for the below too, but it's syntax is slightly different):
Free Cards.Selection = Free Cards.Selection + 5
Free Cards.Selection = Free Cards.Selection * 3 // the * symbol is multiplication operation
Free Cards.Selection = Free Cards.Selection / 2 // the / symbol is division (normal division / finding the quotient) operation
Free Cards.Selection = Free Cards.Selection - 8 // the - symbol is subtraction operation
Free Cards.Selection = Free Cards.Selection % 10 // the % symbol is modulus (division, but it finds the remainder) operation
// -----------
// GUI/Editor:
AddToInventory (Academics Card)
// or:
MoveObject (Academics Card, player) // if haven't changed the default Player Object's name from 'player', of course
// or:
MoveObject (Academics Card, game.pov)
// is the same as, in-code:
Academics Card.parent = game.pov
// or:
Academics Card.parent = player // if haven't changed the default Player Object's name from 'player', of course
hegemonkhan
20 Nov 2016, 18:24the issue is might this part of your code in your previous post:
otherwise {
AddToInventory (Academics Card) // depends on your design, may need to remove this line (leave the 'otherwise' scripting blank)
}
but it could be something else you've done too, I'd need to see your entire game code, as I can't tell from what you've said in your posts (and/or not have said in your posts --- I'm not clairevoyant/telepathic, lol)
....
'archetypes' and 'free cards' are two separate Objects, right? if so, then they shouldn't be causing your issue... if you've set up everything right...
Deckrect
20 Nov 2016, 18:37Oh! Archetypes are like a package, working in game as a player attribute at one instance and as an object.
The player enters a room names Types and there are Objects representing the Archetypes. So, for example, there is an "Rebel Archetype" Object. When the player uses "Look at", the is a text describing its concept and how it works in game. When the player uses "Take", it clones fours different cards to the inventory, sets player.archetype as "Rebel" and then moves player to "Free Cards" room, where the player will pick more extra cards.
hegemonkhan
20 Nov 2016, 18:55okay... so... you got in your inventory (aka: the default 'player' Player Object)
4 Cloned Objects of the 'rebel archetype' (Rebel Archetype2, Rebel Archetype3, etc --- or however quest names the clones), does the 'take' also put the original/actual 'Rebel Archetype' Object into your inventory (aka: the default 'player' Player Object) ??? Or are the 4 Cloned Objects of for other different card Objects (not 4 clones of the 'archetype' Object) ???
(this is why it's so much easier to just have you post your entire game code, lol)
and then in the next room, you select more cards, and these are causing you the issues ??? Are these cards different Objects than the previous object cards in the prior room ???
you've got script that moves a card into your inventory or you to a specific room or whatever... if this keeps happening when it shouldn't... you're referencing that object again, thus the same action is again done to it... or you're working with loops in your scripting... or whatever else... it's hard to think of the infinite things you could be doing, without such detailed explanation, again why just posting your entire game code is so much easier... for us/me. We can see what you're doing, find the isssue, and fix it... VS .... you trying to describe what you've done and also not knowing what's the relevent stuff to the issue as you're not as knowledgeable about coding as we are, at least not yet (as I'm still a code noob myself, sighs)
Deckrect
20 Nov 2016, 19:03Oh! No! When player picks up the "Rebel Archetype" Object, it clones to inventory two copies of the "Burglary Card", one copy of the "Intimidating Card" and one copy of the "Physical Card". Each Card, of course, is an Object. The "Rebel Archetype" Object will never be used again in game and it does not goes to the inventory. It just tells what cards will be added to the inventory, changes the Archetype attribute the player has and then dispatches player to the next room.