• Please note: In an effort to ensure that all of our users feel welcome on our forums, we’ve updated our forum rules. You can review the updated rules here: http://forums.wolflair.com/showthread.php?t=5528.

    If a fellow Community member is not following the forum rules, please report the post by clicking the Report button (the red yield sign on the left) located on every post. This will notify the moderators directly. If you have any questions about these new rules, please contact support@wolflair.com.

    - The Lone Wolf Development Team

Handling units with resource pools

Bluefool

Well-known member
I'm having trouble figuring this out:

val:stat.PtsMax > 0

What should stat.PtsMax be? I thought if the stat was heroiclim, that line should be val:heroiclim.PtsMax, but that won't compile...



var unspent as number
unspent = unit.stat[PtsMax] - unit.stat[PtsUsed]

Same problem here, what exactly is unit.stat[PtsMax], and what is unit.stat[PtsUsed]?
 
Both of these situations are referring to an actual "unit stat". Do you have a unit stat named "heroiclim"? Or is that just a tag you defined?

If it's a unit stat, they just swap in the name of your unit stat for the sample unit stat. In other words, replace "PtsMax" with "heroiclim".

Given that "heroiclim" is 9 characters long, I'm guessing it's just a tag and not an actual unit stat. If it were a unit stat, it would get truncated after only one digit of value, so that's not a good thing. The example assumes you are working with an actual "unit stat" value, which allows you to easily define a different value for each unit if you want.

Hope this helps,
Rob

At 03:29 PM 3/8/2006, you wrote:

I'm having trouble figuring this out:

val:stat.PtsMax > 0

What should stat.PtsMax be? I thought if the stat was heroiclim, that line should be val:heroiclim.PtsMax, but that won't compile...



var unspent as number
unspent = unit.stat[PtsMax] - unit.stat[PtsUsed]

Same problem here, what exactly is unit.stat[PtsMax], and what is unit.stat[PtsUsed]?
 
Um, what? Me make a stat that was 9 charachters long, and only after implementing it in hundreds and hundreds of items and units, only discover the error after trying to fix something else?

Why...um...*chuckle* no no of course not...heh...nope...not me....


Let's see....edit, search record...heroiclim....yup.

Thanks again Rob :).
 
Hmm...well, no, still not working/making sense.

I went through and changed my stat to htl from heroiclim on everything, so it would be under the charachter limit.

So, the stat is htl.

on the very first part of the guide:

After creating an option, then putting that option in a linkset set as global, in the visibilty section I put this:

val:stat.htl > 0

That gets a compile error:

Syntax error in tag expression for 'visibility' option pc.
Tag 'stat.htl' not defined

val:stat.[htl] > 0

gets a similar problem.

Figuring I would try to get the second part working and just have it show up on all the units for a bit, I tried to work out the second part.

I still can not figure out what or where a unit.stat[PtsUsed] would come from. I have one stat defined: htl. Its a numeric value. I understand unit.stat[htl] will return the vaule that the stat is set for for that unit, so I can't use unit.stat[htl] for the other side of the equation or I'm subtracting the same amount from itself???

Or, any data files out there that actually use this method? The ones I looked at (primarily warhammer) use some other method, as I can'f find an item with a global option, or a option with a cost script???
 
the expression will need to read:

val:runtime.htl? > 0

The stat is read from the runtime value and the '?' at the end acts as a 'wildcard' that is converted into a value so the matching occurence of htl is turned into a numeric value, i.e. htl5 would be read as 5

p18 of the pdf in the section on roster gives some info about this, cant find the full reference for all of it though sorry, Rob will prob be able to give a more accurate description of it all though
 
I strongly encourage you to review the following two sections right away. It's quite possible that you've overlooked a few other valuable tidbits, and it would be better to catch them sooner as opposed to later. :-)

1. In the Tips & Tricks chapter, see the section entitled Naming Systems for Unique Ids.
2. In the Distributing Data Filse chapter, see the section entitled Authoring Checklist.

Hope this helps,
Rob

At 05:26 AM 3/11/2006, you wrote:

Um, what? Me make a stat that was 9 charachters long, and only after implementing it in hundreds and hundreds of items and units, only discover the error after trying to fix something else?

Why...um...*chuckle* no no of course not...heh...nope...not me....


Let's see....edit, search record...heroiclim....yup.

Thanks again Rob
icon_smile.gif
.
 
You need to access the information using the appropriate mechanism within each context. Unit stats have their value, which can be accessed via various methods from within scripts. You need to check the docs on the various target references that are available from within each script to determine how to do that (see the chapters on scripting).

In addition, every unit stat has a "runtime" tag that will be automatically defined for it. That tag will always reflect the current value of the stat at the moment the tag is being accessed. If you are trying to access the current value of a stat via a tag expression, then you need to use the "runtime" tag. To do that, you should use the syntax "val:runtime.htl?", just as Harkan suggested.

The problem is that you are trying to use script syntax within the tag expression in your example below. That's why you're getting the compiler errors.

With regards to the "second part" you refer to below, I'm not sure what you're referring to. Please explain and I'll do my best to offer some guidance.

Thanks, Rob


At 10:42 AM 3/11/2006, you wrote:

Hmm...well, no, still not working/making sense.

I went through and changed my stat to htl from heroiclim on everything, so it would be under the charachter limit.

So, the stat is htl.

on the very first part of the guide:

After creating an option, then putting that option in a linkset set as global, in the visibilty section I put this:

val:stat.htl > 0

That gets a compile error:

Syntax error in tag expression for 'visibility' option pc.
Tag 'stat.htl' not defined

val:stat.[htl] > 0

gets a similar problem.

Figuring I would try to get the second part working and just have it show up on all the units for a bit, I tried to work out the second part.

I still can not figure out what or where a unit.stat[PtsUsed] would come from. I have one stat defined: htl. Its a numeric value. I understand unit.stat[htl] will return the vaule that the stat is set for for that unit, so I can't use unit.stat[htl] for the other side of the equation or I'm subtracting the same amount from itself???

Or, any data files out there that actually use this method? The ones I looked at (primarily warhammer) use some other method, as I can'f find an item with a global option, or a option with a cost script???
 
Well, some down, but not yet there. No more compile errors on the visibility, thanks guys! Its got:

val:runtime.htl? > 0

And this makes sense to me.

The "second part" is the second example code block from Handling Units with Resource Pools.

The example is this:

~ Get the number of unspent points
var unspent as number
unspent = unit.stat[PtsMax] - unit.stat[PtsUsed]
~ Determine if more points were used than allowed
var is_exceed as number
if (unspent >= 0) then
is_exceed = 0
else
is_exceed = 1
endif
~ Set the option name to the unspent points remaining and use red if exceeded
name = "Item Points Left: " & unspent
if (is_exceed > 0) then
name = "{text ff0000}" & name & "{text 010101}"
endif


I'm using:

~ Work out how many points of items we're allowed
var result as number
result = unit.stat[htl] - val:runtime.htl?

~ Check to see if I'm over the limit
var is_exceed as number
if (result >= 0) then
is_exceed = 0
else
is_exceed = 1
endif

~ Set the option name to the unspent points remaining and use red if exceeded
name = "HT Points Left: " & result

if (is_exceed > 0) then
name = "{text ff0000}" & name & "{text 010101}"
else
name = "{text 80ff80}" & name & "{text 010101}"
endif

Its defining that val:runtime.htl? sucker; it gives me a compile error every time.

I've read and read read all the doc's mentioned, tried numerous combinations of syntax expression: result = (unit.stat[htl] - val:runtime.htl?), etc

And still compile errors.

As long as I cut out "side two" of the expression:

----------side one--------side two
result = unit.stat[htl] - val:runtime.htl?

It will compile, but of course I never calculate how much of htl got used, so its rather pointless. But, it does let me know thats got to be where I'm still making the error.

So, why is it working in visibility, but not in cost? I've been beating my head into this one for too many hours now to give up, but I'm starting to wonder if a item count was really worth it ;).
 
The syntax "val:runtime.htl?" is explicitly for use within a TAG EXPRESSION. You're trying to use it within a script, so that's why it's not working. When you are writing a tag expression, you must follow the rules outlined in the chapter the fully describes how to use tag expressions. When writing scripts, you must follow the rules outlined for scripts. They are NOT the same thing.

Take a look at the example more closely. You'll see that there are TWO stats being used. One spcifies the maximum number of points that the unit is allowed to spend, and the second specifies the current total number of points that have been spent. You need to do the same thing with the item limit. You need one stat for the limit and another to track the usage. Then you can compare the two to perform the proper verification. You're currently trying to use the same stat for both the limit and the current usage. The only way that can work is if you subtract the usage from the limit for each item and then verify the total is >= 0.

-Rob


At 06:13 PM 3/18/2006, you wrote:

Well, some down, but not yet there. No more compile errors on the visibility, thanks guys! Its got:

val:runtime.htl? > 0

And this makes sense to me.

The "second part" is the second example code block from Handling Units with Resource Pools.

The example is this:

~ Get the number of unspent points
var unspent as number
unspent = unit.stat[PtsMax] - unit.stat[PtsUsed]
~ Determine if more points were used than allowed
var is_exceed as number
if (unspent >= 0) then
is_exceed = 0
else
is_exceed = 1
endif
~ Set the option name to the unspent points remaining and use red if exceeded
name = "Item Points Left: " & unspent
if (is_exceed > 0) then
name = "{text ff0000}" & name & "{text 010101}"
endif


I'm using:

~ Work out how many points of items we're allowed
var result as number
result = unit.stat[htl] - val:runtime.htl?

~ Check to see if I'm over the limit
var is_exceed as number
if (result >= 0) then
is_exceed = 0
else
is_exceed = 1
endif

~ Set the option name to the unspent points remaining and use red if exceeded
name = "HT Points Left: " & result

if (is_exceed > 0) then
name = "{text ff0000}" & name & "{text 010101}"
else
name = "{text 80ff80}" & name & "{text 010101}"
endif

Its defining that val:runtime.htl? sucker; it gives me a compile error every time.

I've read and read read all the doc's mentioned, tried numerous combinations of syntax expression: result = (unit.stat[htl] - val:runtime.htl?), etc

And still compile errors.

As long as I cut out "side two" of the expression:

side one side two
result = unit.stat[htl] - val:runtime.htl?

It will compile, but of course I never calculate how much of htl got used, so its rather pointless. But, it does let me know thats got to be where I'm still making the error.

So, why is it working in visibility, but not in cost? I've been beating my head into this one for too many hours now to give up, but I'm starting to wonder if a item count was really worth it
icon_wink.gif
.
 
OK, I put this aside for a few weeks as it was making less and less sense why I ripped apart a functioning method to try to implement this. That aside now, I took a fresh look at it again after reading the documentation from cover to cover all over yet again.

Take a look at the example more closely. You'll see that there are TWO stats being used.

Thats why I asked why I was subtracting the same thing from itself. I knew that weeks ago, what I've been trying to figure out is how to assign a stat to an item. Since I changed all of this over to item based lists, there is no way I can find, and again after multiple re-reads of the docs, to assign a stat to an item.

So I have one stat that specifies the number of points the unit is allowed to spend assigned to the unit.

Now how do I get a second stat that will be useable in, as you say, a TAG EXPRESSION. The item can have exclusion groups. When I have tried to track that, I got slapped down for trying to use the wrong thing, so I know that can't be it. Well, if we're tracking it with a stat, you can't get an item to have a stat. How are you supposed to generate that second value to subtract??

One spcifies the maximum number of points that the unit is allowed to spend, and the second specifies the current total number of points that have been spent. You need to do the same thing with the item limit. You need one stat for the limit and another to track the usage. Then you can compare the two to perform the proper verification. You're currently trying to use the same stat for both the limit and the current usage. The only way that can work is if you subtract the usage from the limit for each item and then verify the total is >= 0.

So you can't subract something non-existant from something. Suprisingly, I did take first grade math and I knew that. What I need to know, is where in the documentation it talks about how to generate that second stat; becuase I've spent a great deal of time trying to find it and can't.
 
First of all, I wasn't trying to belittle you in my previous response on this topic. I don't have the luxury of knowing "why" you asked a particular question on this end. If you take a look at all the posts we get on AB, there are many questions that are a simple overlooking of something by the user, usually due to the complexity of working with AB. From reading your post, I must have misunderstood things, because I interpreted it differently from your actual intent.

The reason that you aren't being able to figure out how to access stats on items is because they don't exist on items. Based on your example, the example in the docs that you reference, and the previous details of this discussion, I thought you were manipulating items as the children of units. Is that not the case?

In the example within the docs, I realize there are two separate unit stats being managed. But your last post eliminates the reference to the second unit stat, so that's what made me think you were ignoring the other unit stat and trying to solve it with one. I still don't understand why you eliminated the other unit stat, so maybe we need to start there and try moving forward again.

I'm going to assume you ARE managing items as the children of units. If so, the stats you need to be focused on apply to the containing unit. That's where everything gets tallied and is accessible. If an item needs to manipulate a stat, it should be manipulating the stat of the containing unit. This is exactly what's being done within the example in the docs.

At this point, I could easily be completely misunderstanding things, but I'm going to take a guess. I think that what's tripping you up is how to actually tally up the total number of points spent on items by each unit. This can be accomplished quite easily via the use of a special option that you might call "ItemTally". In the Cost script for this option, you would specify the one line below (change the name of the stat to match yours):
    unit.stat[PtsUsed] = unit.stat[PtsUsed] + unit.cost[item]

You then need to assign this option to every unit. You can do this individually, or you can do this the easy way. If you create a linkset can designate it as "global", then add this one option to that linkset, you'll automatically add this option to every entity in the roster. By then modifying the option to specify a Live tagexpr of "entity.unit", you'll limit the option to only apply to every unit. The net result is that every unit automatically tallies the cost of items into the appropriate stat.

I took a look through this entire thread and I don't think you need to access the cost from a tag expression. Was there another thread I need to review? The topic of accessing a stat via tag expression came from your use of such an access in your earlier example. I think that was just a mistake in the usage that ended up sending us down a wrong path.

Anyways, please let me know if this solves the problem for you....

-Rob

At 04:34 AM 3/26/2006, you wrote:

OK, I put this aside for a few weeks as it was making less and less sense why I ripped apart a functioning method to try to implement this. That aside now, I took a fresh look at it again after reading the documentation from cover to cover all over yet again.

Take a look at the example more closely. You'll see that there are TWO stats being used.

Thats why I asked why I was subtracting the same thing from itself. I knew that weeks ago, what I've been trying to figure out is how to assign a stat to an item. Since I changed all of this over to item based lists, there is no way I can find, and again after multiple re-reads of the docs, to assign a stat to an item.

So I have one stat that specifies the number of points the unit is allowed to spend assigned to the unit.

Now how do I get a second stat that will be useable in, as you say, a TAG EXPRESSION. The item can have exclusion groups. When I have tried to track that, I got slapped down for trying to use the wrong thing, so I know that can't be it. Well, if we're tracking it with a stat, you can't get an item to have a stat. How are you supposed to generate that second value to subtract??

One spcifies the maximum number of points that the unit is allowed to spend, and the second specifies the current total number of points that have been spent. You need to do the same thing with the item limit. You need one stat for the limit and another to track the usage. Then you can compare the two to perform the proper verification. You're currently trying to use the same stat for both the limit and the current usage. The only way that can work is if you subtract the usage from the limit for each item and then verify the total is >= 0.

So you can't subract something non-existant from something. Suprisingly, I did take first grade math and I knew that. What I need to know, is where in the documentation it talks about how to generate that second stat; becuase I've spent a great deal of tiem trying to find it and can't.
 
Back
Top