RPTools.net

Discussion and Support

Skip to content

It is currently Fri Feb 23, 2018 11:27 pm 






Reply to topic  [ 7 posts ] 

Previous topic | Next topic 

  Print view

Author Message
 Offline
Kobold
 
Joined: Tue Sep 08, 2015 3:46 am
Posts: 3
 Post subject: Confusion on how to solve this problem
PostPosted: Tue Sep 08, 2015 4:37 am 
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.


Mekton.cmpgn [624.72 KiB]
Downloaded 31 times
Top
 Profile  
 
User avatar  Offline
Great Wyrm
 
Joined: Mon Sep 15, 2008 8:27 am
Posts: 1207
Location: Bristol, UK
 Post subject: Re: Confusion on how to solve this problem
PostPosted: Tue Sep 08, 2015 5:02 am 
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.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9485
Location: Netherlands
 Post subject: Re: Confusion on how to solve this problem
PostPosted: Tue Sep 08, 2015 6:22 am 
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.

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
 Offline
Kobold
 
Joined: Tue Sep 08, 2015 3:46 am
Posts: 3
 Post subject: Re: Confusion on how to solve this problem
PostPosted: Tue Sep 08, 2015 7:54 am 
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.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9485
Location: Netherlands
 Post subject: Re: Confusion on how to solve this problem
PostPosted: Tue Sep 08, 2015 4:33 pm 
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"

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
 Offline
Kobold
 
Joined: Tue Sep 08, 2015 3:46 am
Posts: 3
 Post subject: Re: Confusion on how to solve this problem
PostPosted: Tue Sep 08, 2015 10:24 pm 
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:
[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:
[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.
    };


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9485
Location: Netherlands
 Post subject: Re: Confusion on how to solve this problem
PostPosted: Wed Sep 09, 2015 2:28 am 
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:
[h:hpLost=floor((hpChange-0)*1)]

is a really convoluted way of saying this:
Code:
[h:hpLost=hpChange]

(-0 == no change, *1 == no change)

Then there's this line:
Code:
[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:
[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:
[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(hpChangeLeftArm_Max LeftArm_Current)]
    [
LeftArm_Current    LeftArm_Current diff]
    [if(
diff):message    strformat("%{tok} is healed and gains %{diff} hit points.")]
};{
    [
hpChange                max(0hpChange LeftArmSP_Current)]
    [
diff                    min(hpChangeLeftArm_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

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 7 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 1 guest





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman