Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Accessing a record field using a variable$

Author
Message
AdamRyan
6
Years of Service
User Offline
Joined: 13th Dec 2017
Location:
Posted: 15th Jan 2018 23:25
Imagine a record set as follows

armour[4].type = heavy
armour[4].head = 120
armour[4].body = 42

Then a hit is calculated to have been to the head (not body)

damageArea$ = "head"

Now how can i access armour[4].head ?

armour[4].damageArea$ does not work for example. Is it even possible?

NB this is an oversimplification of the actual code requirements, I do not wish to list a series of if else if else and hardcode the possible record fields.


Supertino
7
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 16th Jan 2018 09:45 Edited at: 16th Jan 2018 09:47
Not sure this is what you want, I don't think its possible to do it the way you're wanting, this is how I'd do it, if it's of any help.

AdamRyan
6
Years of Service
User Offline
Joined: 13th Dec 2017
Location:
Posted: 16th Jan 2018 11:24
Thanks Supertino!

I like your thinking and I will have a look at trying it this way or having a record.field = array too.

(Really hoping to avoid hard coding anything... but I-ll see)

Thanks again, much appreciated!
Adam
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 16th Jan 2018 14:26
I would be sorely tempted to standardise it all, so every item of armour has a head, torso, arm, leg, and foot value. That way, you could just use a 2D array against the item itself, to work out the armour rating. Just thinking that the code might get a bit more complex if you don't make the assumption that armour can protect any part, or several parts of the body. You would need to know the damage at which part of the body, but then you can set an index to that particular area - if you have Item[Id,Area] for example, and head is always Area 1, then you'd set an index variable to 1 and get the armour value directly.

Know what I mean? - instead of saying this helmet protects the head at a rating of 10.0 - you'd say this helmet protects the heat at 10.0, the torso at 1.0, the legs at 0.0, arms at 0.0. A magic cloak for example, might actually protect the torso, arms and legs... it's a lot easier to just grab the armour values and apply them, than have to work out which area the armour value applies to. Mostly, it's good practice to avoid unnecessary string comparisons, especially with something that is checked very often. This could allow you to apply damage to more than one area at a time - like a fireball might hit someone in the torso, but also cause damage to other body parts... some weapons might have ambient damage that can be applied, magic, fire, ice etc. And if you have no armour on your feet, maybe the legs get damage applied as well. You would have to code this stuff of course, but probably only for when an attack has happened, and you get a lot of control over things and can add intricate rules without needing lots of repetitive code. The array would take care of the tedious stuff, and you'd be left to code the intricate rules, but there's no reason why that can't be neat and efficient.

I think that people are getting more and more into games that have complex rule sets like that, when gear isn't just a positive or negative value. Seeing more complex rule sets in survival RPG games these days for example.
The code is dark and full of errors
AdamRyan
6
Years of Service
User Offline
Joined: 13th Dec 2017
Location:
Posted: 16th Jan 2018 21:07
Thanks Van B!

I think you may be right about arrays. Grouping the values in fixed length arrays (both for weapon damage and armour damage rec'd) and then looping through could solve some of the situations. Thanks.

For other situations Supertino #constants are the way to go. For still others i am looking at using hash arrays.

Thanks guys!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Jan 2018 21:26




The armor property references the base properties of the type of armor the player is currently equipped to wear. The stats of that armor are copied into armorStats because you may want to change the stats of the armor being worn (but not the original piece in the game). For instance, a bonus that adds +5 to head. Or, maybe the armor can take damage and become less effective.


Then you can adjust the damage against areas like this:


You can then figure out some kind of formula to use to calculate damage. Like certain areas have a multiplier. Say you took a hit of 20 damage to the head, the head would take 1.2x more damage from the attack thus totaling 24 points. But then you'd have to calculate how much the armor can reduce that damage before then subtracting it from the player's health.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 16th Jan 2018 22:13
Good explanation....

Plus...I've always wanted a game where i could wear .... "The Royal Bikini Robes of Saint Jenny"
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Jan 2018 16:48
Great chest protection, but if you must wade through the swamps of scantalar, your legs will be left exposed to the elements and you may die of dysentery.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
AdamRyan
6
Years of Service
User Offline
Joined: 13th Dec 2017
Location:
Posted: 18th Jan 2018 09:13
Thanks Phaelax! I like your thinking however will need to structure differently to avoid 200 else if statements...

Login to post a reply

Server time is: 2024-11-21 19:19:03
Your offset time is: 2024-11-21 19:19:03