Confusion on how to solve this problem

If you have searched the other User Creations subforums and an answer to your question has not been found, please post here!

Moderators: dorpond, trevor, Azhrei, Gamerdude

Post Reply
drpeanut779
Kobold
Posts: 3
Joined: Tue Sep 08, 2015 4:46 am

Confusion on how to solve this problem

Post by drpeanut779 »

Hello everyone! Long time lurker and user of maptools here.

I currently am working on a Mekton Zeta framework that involves a lot of dynamic macros. With this I will try to go into detail in exactly what is puzzling me.

As it stands right now I have defined a bunch of properties.
Example:

Part1hp
Part1hp_current
Part1sp
Part1sp_current
Part2hp
Part2hp_current
Part2sp
Part2sp_current

What I am looking to do with these properties is to allow the players to dynamically name them.
My knowledge is rather limited and I don't even know if this can be done.

Example:
Part1hp is now MechTorso
Part1hp_current is now MechTorso_current

Part2hp is now MechTorsoSP
Part2hp_current is now MechTorsoSP_current

Now I know that looks ugly but I hope I am making my point clear.
If the properties cannot be renamed dynamically I would like to use a macro to "name" them or refer to them not by their base name somehow.
Reason why the naming is so important is due to the system I am using which allows the players to add or remove "parts".

Essentially I am designing a macro to track damage and armor.

Here is what I wish the macro to do:

Would prompt an input for a value for how much damage was taken.
Then there would be radio buttons which would reference each property (aka each part)
Once a radio button was ticked then it would reference the "HP" then reference another property (SP) much like how DR works with the pathfinder frameworks.
Except the SP in this system degrades and would need to be able to be subtracted.

Example:

Player 1 takes 23 points of damage.

Next Prompt
Damage taken:
How much damage is ignored? [enter value]
Lists the SP value.

I will upload the campaign file for anyone who wishes to take a look.
Lastly I want to thank you for your time and effort.
Attachments
Mekton.cmpgn
(624.72 KiB) Downloaded 63 times

User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

Re: Confusion on how to solve this problem

Post by Jagged »

This sounds like a job for JSON!

I think might want to take a look at some of the JSON tutorials and see if that does what you need.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Confusion on how to solve this problem

Post by wolph42 »

if there is a limited amount of possible properties I would suggest to define them all. Only the ones actually used show up in the stat sheet.
Should there be an unlimited amount of possible properties then I would suggest a 'general' property scheme supported by json objects to keep track of the specifics.

drpeanut779
Kobold
Posts: 3
Joined: Tue Sep 08, 2015 4:46 am

Re: Confusion on how to solve this problem

Post by drpeanut779 »

Matter of fact there are a set amount of "parts" or in this case properties.
The limit is 15 "Parts".

Example:

Part1hp
Part1hp_current
Part1sp
Part1sp_current

etc..etc..

Part15hp
Part15hp_current
Part15sp
Part15sp_current

I have read the json wiki and it doesn't seem to make much sense to me and forgive me I am rather new at coding in general.
Is there potentially a newbie friendly options to tackle this problem? Recently I was checking out "Switch" commands wiki but it seemed like it wasn't what I was looking for.
Also I would like to thank you two for such a quick response.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Confusion on how to solve this problem

Post by wolph42 »

json is baiscally a dynamic database system, which works with keys and value (quite similar to variable and value).
Its structure is this:
{key1:value1, key2;value2, etc.} In you case you could thus define your properties for one character
{part1:MechTorso, part2:MechArm, etc.}
to create the above you do:
[partNames = json.set("{}", "Part1", "MechTorso", "Part2", "MechArm", etc.)]
to retrieve a part:
[part1 = json.get(partNames, "Part1")]
which will return "MechTorso"

drpeanut779
Kobold
Posts: 3
Joined: Tue Sep 08, 2015 4:46 am

Re: Confusion on how to solve this problem

Post by drpeanut779 »

wolph42 wrote:json is baiscally a dynamic database system, which works with keys and value (quite similar to variable and value).
Its structure is this:
{key1:value1, key2;value2, etc.} In you case you could thus define your properties for one character
{part1:MechTorso, part2:MechArm, etc.}
to create the above you do:
[partNames = json.set("{}", "Part1", "MechTorso", "Part2", "MechArm", etc.)]
to retrieve a part:
[part1 = json.get(partNames, "Part1")]
which will return "MechTorso"
Thanks for the advice and I think I will be taking a different approach to the problem now.
The naming of each property is no longer required as I found a nice workaround for that.
Now whats left is assigning damage and reducing that damage with another property.

Code: Select all

[h:LeftArm_Max]
[h:LeftArm_Current]
[h:LeftArmSP]
[h:LeftArmSP_Current]



  [h:status = input(
    "hpChange|0|Number of Hit Points",
    "dmgOrHealing|Damage,Healing|Is the character taking damage or being healed?|RADIO|SELECT=0")]
    [h:abort(status)]
    [if(dmgOrHealing == 0),CODE:
    {
    [h:hpLost=floor((hpChange-0)*1)]

        [h:Total = hpChange-LeftArmSP_Current]

[if(Total > 0), CODE:
 {
        [h:LeftArmSP_Current = LeftArmSP_Current-1]
};{
        [h:LeftArmSP_Current = LeftArmSP_Current]
}
]


    [if(hpLost > 0),CODE:
    {

        [h:LeftArm_Current = LeftArm_Current-Total]
        [r:token.name] loses [r:Total] hit points and has [r:LeftArmSP_Current] Armor remaining.
    };
    {
    [r:token.name] loses no hit points.
    };]
    };
    {
        [h:diff = LeftArm_Max - LeftArm_Current]
        [h:LeftArm_Current = min(LeftArm_Current+hpChange, LeftArm_Max)]
       [r:token.name] is healed and gains  [r:min(diff,hpChange)] hit points. 
    };]

[if(LeftArmSP_Current < 0), CODE:
 {
        [h:LeftArmSP_Current = 0]
};{
        [h:LeftArmSP_Current = LeftArmSP_Current]
}
]
Here is what I got so far in assigning damage to a certain piece.
As you can see there I am trying to apply a value either as "damage" or "healing".
Then reduce the damage by another property.
After it checks that damage has been done I am trying to make sure the property that is reducing the damage goes down by -1 every time.
Another problem I am running into is that there is a negative value for whatever reason it essentially "changes" the HP/current value.
Furthermore I am unsure on how to floor and ceiling these properties such as LeftArm_Max is the total that property can be and you can't go below zero.
So what I have done here is essentially made [code():] function that sets the values to zero once they go below zero.
For addressing the problem of when they go above their "max" I do not know.
My gut is telling me that maybe an abort() function may work if the number is negative.

I believe this piece of code is causing the problem with the changing hp/current values.

Code: Select all

[if(hpLost > 0),CODE:
    {

        [h:LeftArm_Current = LeftArm_Current-Total]
        [r:token.name] loses [r:Total] hit points and has [r:LeftArmSP_Current] Armor remaining.
    };

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Confusion on how to solve this problem

Post by wolph42 »

edit: ok I went through your code and its quite funky. For one you have some syntax errors, like };] the ; should not be there. Also the indentation is quite off making it very bug prone and hard to debug.
Also this:

Code: Select all

[h:hpLost=floor((hpChange-0)*1)]
is a really convoluted way of saying this:

Code: Select all

[h:hpLost=hpChange]
(-0 == no change, *1 == no change)

Then there's this line:

Code: Select all

[h:LeftArmSP_Current = LeftArmSP_Current]
why do you put it there?? It doesn't do anything.
Also you ONLY need a 'CODE' block if you want to put more than one line in it. So rewriting your code a bit you get:

Code: Select all

[h:LeftArm_Max]
[h:LeftArm_Current]
[h:LeftArmSP]
[h:LeftArmSP_Current]

[h:status = input(
"hpChange|0|Number of Hit Points",
"dmgOrHealing|Damage,Healing|Is the character taking damage or being healed?|RADIO|SELECT=0")]
[h:abort(status)]

[if(dmgOrHealing == 0),CODE:{
    [h:hpLost=floor((hpChange-0)*1)]
    [h:Total = hpChange-LeftArmSP_Current]
    [h,if(Total > 0):LeftArmSP_Current = LeftArmSP_Current-1]
    [if(hpLost > 0),CODE:{
        [h:LeftArm_Current = LeftArm_Current-Total]
        [r:token.name] loses [r:Total] hit points and has [r:LeftArmSP_Current] Armor remaining.
    };{
        [r:token.name] loses no hit points.
    }]
};{
    [h:diff = LeftArm_Max - LeftArm_Current]
    [h:LeftArm_Current = min(LeftArm_Current+hpChange, LeftArm_Max)]
    [r:token.name] is healed and gains  [r:min(diff,hpChange)] hit points. 
};]

[h, if(LeftArmSP_Current < 0):LeftArmSP_Current = 0 ; LeftArmSP_Current = LeftArmSP_Current]
 

now here's how I would do it:

Couple of remarks:
- if statements work with 0 (==false) and 1 or higher(==true). Where 12==13 will thus return '0' and 12==12 will return '1'. Hence if you have to options (as you have in your input) you can leverage that as one option is '0' and the other is '1'. Note thus that e.g. '5' is also 'TRUE, only '0' is false.
- general rule: try to ALWAYS employ the following structure:
INITIALIZE (get arguments, preset variables, etc)
INPUT (ask questions to user)
PROCESS (data)
OUTPUT (messages)
This makes your code clean and understandable.
- always indent CODE blocks correctly
- you don't use LeftArmSP anywhere in your code, so im guessing its function (and im guessing its also a 'max')

Code: Select all

[h:'<!-- ----------------------FUNCTION NAME (ARGUMENTS, if any) ------------------------------ -->']

<!-- INITIALIZE  -->

[h:LeftArm_Max            = 10]
[h:LeftArm_Current        = 5]
[h:LeftArmSP_Max        = 12]
[h:LeftArmSP_Current    = 6]

[h:tok        = getSelectedNames()]
[h:assert(listCount(tok)==1,"Make sure (only) ONE token is selected",0)]
[h:message    = strformat("The action has no effect, %{tok} neither receives nor looses any hit points")]

<!-- INPUT -->

[h:abort(input(
    "hpChange|0|Number of Hit Points",
    "doHeal|Damage,Healing|Is the character taking damage or being healed?|RADIO|SELECT=0"
))]

<!-- PROCESS  -->
<pre>
[if(doHeal),CODE:{
    [diff                = min(hpChange, LeftArm_Max - LeftArm_Current)]
    [LeftArm_Current    = LeftArm_Current + diff]
    [if(diff):message    = strformat("%{tok} is healed and gains %{diff} hit points.")]
};{
    [hpChange                = max(0, hpChange - LeftArmSP_Current)]
    [diff                    = min(hpChange, LeftArm_Current)]
    [if(diff), CODE:{
        [LeftArmSP_Current    = max(0,LeftArmSP_Current-1)]
        [LeftArm_Current    = LeftArm_Current - diff]
        [message            = strformat("%{tok} looses %{diff} hit points and has %{LeftArmSP_Current} armour remaining")]
    };{}]
};]

<!-- OUTPUT  -->
[r:message] 

Post Reply

Return to “Requests for HELLLLP!”