Scripts / What is "ai_old_health[e]"?

Author
Message
Moshroom
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location: Finland
Posted: 29th Sep 2015 14:52
The total lack of any useful comments in the default lua files has caused me frustration more than once, but usually I have eventually managed to guess what the GameGuru's LUA commands and variables/tables are supposed to do. But this time I'm clueless. In the ai_fantasy character script there is this (lines 122 - 125):

I have no idea of the meaning of these lines except that in the end it plays sound. Could somebody be kind to explain me what information does the "ai_old_health" table contain?
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 29th Sep 2015 15:29
Quote: "ai_old_health[e] = g_Entity[e]['health']"

it holds the health and basically tells the character to play a sound whenever he takes damage
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 29th Sep 2015 16:49
AI_Old_Health, the clue is in the array name. When you take damage, as smallg points out above, your health reduces. Oldhealth is updated to reflect this. You need old health, so you can check how much damage you have received or if you were hit and other such things by comparing the two.


SPECS: Q6600 CPU. Nvidia 660GTX. 8 Gig Memory. Win 7.
Bored of the Rings
GameGuru Master
19
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 29th Sep 2015 20:37
As smallg says its the original or previous health value
Professional Programmer: Languages- SAS, C++, SQL, PL-SQL, JavaScript, HTML, Darkbasic Pro, Purebasic, others
Hardware: Dell Precision 490; AMD Radeon HD 7570; LG TFT monitor (widescreen).
Interests: Drumming, Saxophone, Art, Theatre, Music.
Moshroom
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location: Finland
Posted: 1st Oct 2015 07:42
Thanks everyone. Now that you said it, it seems completely logical. In other words, ai_old_health[e] is just a table that is used to store data that's pulled from the engine by another command. I still don't understand why the table is defined this way:

Is there some reason to initiate it with placeholder value -1 instead of just letting it be nil until used? For example:
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 1st Oct 2015 09:17
Nope, that's just how they've chosen to do it
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 1st Oct 2015 17:10
Using a -1 flag is just one method of using flags that should never check for less than zero. It's fairly common practise to use -1 to switch a flag off so 0 and 1 or more can be used. Just one of many ways to do the same thing


SPECS: Q6600 CPU. Nvidia 660GTX. 8 Gig Memory. Win 7.

Login to post a reply

Server time is: 2024-12-22 07:27:52
Your offset time is: 2024-12-22 07:27:52