Best Practice?

onimike
20 Sept 2016, 15:57Hey all! Just wanted to ask what would be the best way to handle multiple weapons? As of now im using a attack verb on enemy then using if scripts to check and see what weapon is being held, so here is a tid bit of the way im doing it
if (game.pov.Weapon = "") {
msg ("What are you trying to attack with! You need to equip a weapon first.")
}
else if (game.pov.Weapon = "Handgun") {
if (Handgun.rounds > 0) {
DecreaseObjectCounter (Handgun, "rounds")
this.Health = this.Health - game.pov.Damage
}
else {
msg ("Need to reload!")
}
}
else if (game.pov.Weapon = "Survival_Knife") {
this.Health = this.Health - game.pov.Damage
}
else if (game.pov.Weapon = "Shotgun") {
if (Shotgun.rounds > 0) {
DecreaseObjectCounter (Shotgun, "rounds")
this.Health = this.Health - game.pov.Damage
}
else {
msg ("Need to reload!")
}
}
else if (game.pov.Weapon = "Assualt_Shotgun") {
if (Assualt_Shotgun.rounds > 0) {
DecreaseObjectCounter (Assualt_Shotgun, "rounds")
this.Health = this.Health - game.pov.Damage
}
else {
msg ("Need to reload!")
}
}
And I have about 10 more weapons to go, is this the best practice?
The Pixie
20 Sept 2016, 17:54I would have game.pov.Weapon would hold the object not the string. Then set up attributes on each one, for ammo and damage done (and accuracy, etc?).
if (game.pov.Weapon = null) {
msg ("What are you trying to attack with! You need to equip a weapon first.")
}
else {
if (HasInt(game.pov.Weapon, "rounds")) {
if (game.pov.Weapon.rounds > 0) {
DecreaseObjectCounter (Handgun, "rounds")
this.Health = this.Health - game.pov.Weapon.Damage
}
else {
msg ("Need to reload!")
}
}
else {
this.Health = this.Health - game.pov.Weapon.Damage
}
}
hegemonkhan
20 Sept 2016, 18:52Unfortunately, for a code noob like me, "best" is a never-ending process, as I'm constantly learning more about how to code, and thus how to code/design better... It's been 4 years... of constantly changing to a "better" code design... lol.
Just don't get too attached... use what you can do... and if what you want to do, requires something better, then and only then, do you then stop and try to learn to do something better, otherwise, you'll keep revising your same code or part of your game, over and over, again... laughs. Being a perfectionist (but, in training, in terms of coding, lol) is a bit of a curse, lol. I'm always looking at my code, and asking... I know this can be done better, how? And I end up never moving on, and advancing on making progress on my game.
Of course, you can always ask for others to help/give you some better code/design, too.
my current level of knowledge would be similiar to Chase's Wearables Library, working with using Lists for handling multiple weapons/armors and layers/levels and slots/body-parts, as I'm still struggling to understand and train my brain in (Abstract) Object-Oriented Design/Programming / Data Structures, as my brain is definately more procedural in thinking/mindset, at least currently (hopefully, my brain will start to learn abstractness/OOP/OOD better, sighs).
As Pixie points out, learn Object (and/or Object List) Attributes, well. Learn the (rest of the) Attribute/Data Types, so you know what you got to work with:
http://docs.textadventures.co.uk/quest/types/ (Attribute/Data Types)
http://docs.textadventures.co.uk/quest/types/object.html (Object Attribute)
http://docs.textadventures.co.uk/quest/types/objectlist.html (Object List Attribute)
think of an Object Attribute as a school P.E. class roster with a single student's name on it, which can be used to bark orders to that student, but obviously the student is not actually/physically on/in that student roster, lol. That's an Object Attribute.
Same with an Object List Attribute, except that the "roster" isn't limited to a single student's name. An Object List Attribute is a normal school P.E. class student roster, having multiple student names on it.
<object name="player">
// an Object Attribute:
<attr name="face_wear_slot_body_part" type="object">glasses</attr>
// some Object List Attributes:
<attr name="foot_wear_slot_body_part" type="objectlist">sock; shoe</attr>
<attr name="torso_wear_slot_body_part" type="objectlist">under_shirt; shirt; sweater; jacket; raincoat</attr> // You must in in Antarctica, lol
<attr name="waist_wear_slot_body_part" type="objectlist">boxers; pants</attr>
// etc Attributes
</object>
<object name="glasses"></object>
<object name="under_shirt"></object>
<object name="shirt"></object>
<object name="sweater"></object>
<object name="jacket"></object>
<object name="raincoat"></object>
<object name="socks"></object>
<object name="shoes"></object>
<object name="boxers"></object>
<object name="pants"></object>
for example:
Q1. where is the 'sword' Object actually/physically located?
Q2. How many 'sword' Objects are there?
<object name="player">
<attr name="right_hand" type="object">sword</attr>
</object>
<object name="player2">
<attr name="right_hand" type="object">sword</attr>
</object>
<object name="global_data_object">
<object name="sword">
<attr name="damage" type="int">50</attr>
</object>
</object>
A1: in the 'global_data_object' Object
A2: 1
but, we can do actions upon/with/using the 'sword' Object (and its Attributes) through the 'player.right_hand' and 'player2.right_hand' Object Attributes of the 'player' and 'player2' Player Objects.

onimike
20 Sept 2016, 22:44Oh very nice both of you. Pixie thats a awesome idea thank you for the example I knew their had to be an easier way.
HK thanks as well for the examples funny i was thing of adding armor to game so these will be nice to reference.
Thanks again
Mike
The Pixie
21 Sept 2016, 07:02Have you had a look at my combat library:
http://textadventures.co.uk/forum/samples/topic/4886/rpg-style-combat-library
It does all this stuff. Even if you do not use it, you might get ideas. I am planning to release an updated version, based on what I learn developing Deeper at some point, but probably not soon.

onimike
21 Sept 2016, 14:53Will do that Pixie been exploring the library's alot more now that I know you can open and edit in notepad++ so making things alot more interesting being able to change and add features 😉
Thanks as always
Mike
hegemonkhan
22 Sept 2016, 05:49@ Onimike:
if you don't know, at the top bar in the notepad++, under languages, choose 'xml' as it seems to work fine (don't seem to be any discrepencies between it and quest's language as far as I can well - in terms of notepad's color-coding of it), which will give you the color-coding help with reading, writing, and troubleshooting your code.

onimike
22 Sept 2016, 07:02@HK oh very nice thank you thats awesome should come in handy.
Mike
hegemonkhan
22 Sept 2016, 20:19color-coding the syntax/code lines is very helpful for programming, experts (jay, pixie, pertex, etc) and noobs (me and you), alike, laughs :D
now most (programming) editors and IDE/SDKs do it now. I'd hate to not have color-coding... it'd make it so much harder... can't imagine not having it, lol. It just makes it so much easier to spot/distinguish lines/parts of code/syntax/lines:
notepad vs notepad++
Never use notepad ever again! So difficult to use notepad without the color coding... maybe we get too spoiled... but why waste your own time, when a machine can do it for you (from someone coding/programming it in for that machine to do it for you)? Isn't that the whole point of computers/machines, to do stuff we don't want to do or can't do or can't do it more effectively? hehe :D