Setting, Finding, and Rolling Skills/Stats with an Search

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

libavf
Cave Troll
Posts: 26
Joined: Fri Jan 18, 2013 2:48 pm

Setting, Finding, and Rolling Skills/Stats with an Search

Post by libavf »

Maybe I am missing this, but in an effort to try to clean up my Campaign Properties I am looking to find a different way to set up macros to find properties on a token automatically and then have them put up in an input window or skill check drop down list.

Ex of current Skill edit:
Spoiler

Code: Select all

[h: input(
"Blunt|" +Blunt+ "|",
"Flail|" +Flail+ "|",
"Slashing|" +Slashing+ "|",
"Piercing|" +Piercing+ "|",
"Martial|" +Martial+ "|",
"H2H|" +Handtohand+ "|",
"Missile|" +Missile+ "|",
"Thrown|" +Throwing+ "|"
)]
This lets me change the skills as a list. I don't need more functionality than that for my players.
What I want is to add a "Sw" tag on the front of each of those to bring up "Skill: Weapons" as the macro to edit these, and a different button to do a skill check vs. these. Right now the best I have is:
Spoiler

Code: Select all

[h: input(
"Skill|Blunt,Flail,Slashing,Piercing,Martial,H2H,Missile,Thrown|Skill|LIST|VALUE=0",
"SkillMod|0|Mod"
)]

Skill: [skv = listget("Blunt,Flail,Slashing,Piercing,Martial,H2H,Missile,Thrown",Skill)]<br/>

Value: [sval = getProperty(skv)]<br/>
Again, easy enough but it doesn't allow for more skills.
This is what I am resorting to at the moment for one of my real problem ones. I am going to have to edit it for each character.
Spoiler

Code: Select all

[h: input(
"Sk1|" +getProperty("ChangeMe1")+ "|Crafting - ",
"Sk2|" +getProperty("ChangeMe2")+ "|Skill2",
"Sk3|" +getProperty("ChangeMe3")+ "|Skill3",
"Sk4|" +getProperty("ChangeMe4")+ "|Skill4",
"Sk5|" +getProperty("ChangeMe5")+ "|Skill5",
"Sk6|" +getProperty("ChangeMe6")+ "|Skill6"
)]

[setProperty("ChangeMe1",Sk1)]
[setProperty("ChangeMe2",Sk2)]
[setProperty("ChangeMe3",Sk3)]
[setProperty("ChangeMe4",Sk4)]
[setProperty("ChangeMe5",Sk5)]
[setProperty("ChangeMe6",Sk6)]
But I don't have a skill check button yet. That is why I am asking. Changing it in two spots will SUCK!

I want to allow for special skills to be added that I just don't want to build in because they are not necessary, nor do I want to give the players ideas.

I am looking for groups of Sm (Skill: Magic), Sg (Skill: General), Sc (Skill: Crafting), Sk (Skill: Knowledge), St (Stats). I don't know if I will need a special marker character like * or & or something to delineate from things that start with those letters. The biggest bothers are the crafting and knowledge skills, and that is what brought up the need for this question.

I tried looking, but I am not finding anything that looks close to an answer for this. Is there some sort of wildcard lookup that I can use, or the foreach, or something else? I am a simpleton when it comes to the macros. I don't have a Library Token and I am trying to stay away from one.

Let me know if I can fill in any blanks.

*edit* I have set up a lib token

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

Re: Setting, Finding, and Rolling Skills/Stats with an Searc

Post by wolph42 »

Im not understanding what youre asking for. Maybe you can give an example charactersheet?
I did notice that you can write this

Code: Select all

[h: input(
"Skill|Blunt,Flail,Slashing,Piercing,Martial,H2H,Missile,Thrown|Skill|LIST|VALUE=0",
"SkillMod|0|Mod"
)]

Skill: [skv = listget("Blunt,Flail,Slashing,Piercing,Martial,H2H,Missile,Thrown",Skill)]<br/>

Value: [sval = getProperty(skv)]<br/>
As this

Code: Select all

[h: input(
"Skill|Blunt,Flail,Slashing,Piercing,Martial,H2H,Missile,Thrown|Skill|LIST|VALUE=STRING",
"SkillMod|0|Mod"
)]

Skill: [r: Skill]

Value: [r:sval = getProperty(Skill)]<br/>

User avatar
metatheurgist
Dragon
Posts: 364
Joined: Mon Oct 26, 2009 5:51 am

Re: Setting, Finding, and Rolling Skills/Stats with an Searc

Post by metatheurgist »

I believe what the OP is saying is he has a macro for setting and rolling skills which is based on a static list, which he currently has to modify for every token and for special circumstances like crafting. He wants to know if there's a better approach.

If I've guessed right it would seem it's time for the OP to learn data structures.

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

Re: Setting, Finding, and Rolling Skills/Stats with an Searc

Post by wolph42 »

metatheurgist wrote:I believe what the OP is saying is he has a macro for setting and rolling skills which is based on a static list, which he currently has to modify for every token and for special circumstances like crafting. He wants to know if there's a better approach.

If I've guessed right it would seem it's time for the OP to learn data structures.
if what you say is correct than indeed i would suggest learning json objects.

libavf
Cave Troll
Posts: 26
Joined: Fri Jan 18, 2013 2:48 pm

Re: Setting, Finding, and Rolling Skills/Stats with an Searc

Post by libavf »

ugg, json objects.

They look WAAAAYYY complicated, but I guess if I can start simple I can get it. I think I am getting the libtoken thing now.

Guess it is time for the next thing. Where should I begin, and can you give me an example code to do a lookup of something?
How do I get a list of token properties that start with "Sc*" for example? That would cover my Skill: Crafting. I am hoping that this will bring up properties not in the campaign props too. Would it?

Thanks!

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

Re: Setting, Finding, and Rolling Skills/Stats with an Searc

Post by wolph42 »

you would store all skill in a json object e.g.

skills:{"ride":2, "hide":5, "Craft Books":6}

to create the above:

Code: Select all

 [skills = json.set("{}", "ride", 2, "hide", 5, "Craft Books", 6)]
To retrieve a value e.g. hide;

Code: Select all

hide: [r:vHide = json.get(skills, "hide")] 
now you can choose to 'nest' a json object inside an object e.g.

skills:{"ride":2, "hide":5, "Craft Skills":{Books:6, Pots:5}, "sneak":3}
This is a bit trickier to create as you FIRST create the nested object and then you create its 'mother'. So:

Code: Select all

[craftSkill = json.set("{}", "Books",6,"Pots",5)]
[skills = json.set("{}", "ride", 2, "hide", 5, "Craft Skills", craftSkill, sneak, 3)] 
Notice the placement of the "quotes". The essence of a json object is that you realise that it works with key:value pairs. Thus in front of the : is the key and after the value. Retrieving a value is thus done by its key. And a value can be anything so also an entire json object. Retrieving the value in this case:

Code: Select all

[h:craftSkills = json.get(skills, "Craft Skills")]
Book making: [r:vBook = json.get(craftSkills , "Books")] 

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Setting, Finding, and Rolling Skills/Stats with an Searc

Post by aliasmask »

JSONs aren't so bad, but I do recommend keeping your structures simple and one dimensional, two at most. A JSON is just a normal string but with a special format. If I were to manually create a json array it would look like this:

Code: Select all

["one","two","three"]
But you should create it like this:

Code: Select all

[H: myArray = json.append("","one","two","three")]
An array is just a list of items. The first element in an array starts at 0. So, if I wanted to get the 3rd element in the array I would do this:

Code: Select all

[H: third = json.get(myArray,2)]
A json object is a lot like an array, but instead of referencing each element with a number, you give it a name or a "key", like this:

Code: Select all

[H: myObj = json.set("{}","key1","one","key2","two","key3","three")]
If I want to get whatever key2 is holding I would do this:

Code: Select all

[H: key2 = json.get(myObj,"key2")]
Note there is a difference when using names and variables. Variables have no quotes, but the name of a key does. This is an important distinction later when using things like the Wiki: eval() function.

Here's is another link talking about some json functions: http://forums.rptools.net/viewtopic.php ... 25#p249525

edit: ninja'd, but I'm sure the more examples the better.

libavf
Cave Troll
Posts: 26
Joined: Fri Jan 18, 2013 2:48 pm

Re: Setting, Finding, and Rolling Skills/Stats with an Searc

Post by libavf »

What I am seeing does not look dynamic. What I am looking for is something more dynamic. I guess my goal is to have to set a property once (using setProperty()) and then bring it up in an input form that auto-fills for that skill type so the players can edit them all on the fly. Not all skill groups have this flexibility, but the crafting/knowledge ones sure do.

It is looking like with the json object that I have to fill in all of the possible values beforehand (maybe I am missing something). I don't know them all. This is where I let the player be creative and if they want Crafting: Armor then cool, if they want Crafting: Shieldsmith then cool too, but if they want Crafting: Poopsmith then I will never see it coming and I just might allow it for the comedic effect.

I can set a property that is not in the campaign properties list, but I just don't know the method to bring it up without doing a rewriting of the macro. I just really want a wildcard operator to bring up all values starting with "Sc*" or some such (like with getProperty(), or getPropertyNamesRaw(), or ...).

What I have found that sort of works is:
Spoiler

Code: Select all

[h: input(
"Skill|" +listGet(getPropertyNamesRaw(),0,":")+ "|Skill|LIST|VALUE=0",
"SkillMod|0|Mod"
)]

Skill: [skv = listGet(getPropertyNamesRaw(),skill)]<br/>
Value: [getProperty(skv)]<br/>
Mod: [SkillMod]
But it brings up EVERYTHING, not just the group I want. Is there a way to throw in a "look for things that start with this" option?

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Setting, Finding, and Rolling Skills/Stats with an Searc

Post by CoveredInFish »

I think you have to filter by hand.

So get all properties(Wiki: getPropertyNamesRaw()), run through that list ([foreach:]) and add all results that you want (eg you can check with Wiki: startsWith()) to a new list (Wiki: listAppend() / Wiki: json.append()). Voila.

Its a bit cumbersome so I would create a user-defined function to filter a list (following the same approach).
example of such a UDF

Code: Select all

[h: "<!-- UDF: filterListStartsWith(stringList, filterString) -->"]
[h: "<!-- this is untested, unpolished code -->"]
[h: "<!-- ========= ========= ========= ========= -->"]
[h: list= arg(0)]
[h: filter = arg(1)]
[h: result = ""]
[h, foreach(item, list), if(startsWith(item, filter): result = listAppend(result, item)]
[h: macro.return = result]
This might be not the most elegant solution (and I too would go for a more flexible, json-based approach) but it will work fine and doesnt require you to rewrite all stuff (there might be benefit in it anyway, cannot say since I dont know your code nor your future plans)

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

Re: Setting, Finding, and Rolling Skills/Stats with an Searc

Post by wolph42 »

What I am seeing does not look dynamic.
but it is!
What I am looking for is something more dynamic.
which it is.

Actually that which what you are proposing is uncontrollable and messy. You will create tokens with hidden properties and whatnot and sooner or later you will run into 'strange' bugs because of these.

You can follow CIF's approach but I don't recommend it.

For the record: you do NOT need to predefine the json keys. You can create them on the fly EXACTLY as you want it. If you want to retrieve all the keys (to see which skills have been made) you can use Wiki: json.fields(). This will return a list through which you can loop to get the respective values.

Additionally you can build an input function around this json so players can add stuff. My suggestion would be to put the 'free' skills inside a nested json e.g. 'trade skills'

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Setting, Finding, and Rolling Skills/Stats with an Searc

Post by CoveredInFish »

wolph42 wrote: You can follow CIF's approach but I don't recommend it.
To be clear - I dont recommend it either. Always better to do it the right way even if it means more work in the beginning. You will benefit later on. But it will work and many roads lead to rome.

User avatar
Bone White
Great Wyrm
Posts: 1124
Joined: Tue Aug 23, 2011 11:41 am
Location: Cornwall, UK

Re: Setting, Finding, and Rolling Skills/Stats with an Searc

Post by Bone White »

Let me try to explain...

The variables you store inside your macros have a name, and a value. e.g.

[code][x = 5][/code]x is the name of the variable, and 5 is the value. When you call [x], 5 is returned.



This is the exact same principle as json objects:

[code][jsonName = json.set("","x",5)][/code]x is the name (or key) of the variable, and 5 is the value. When you call [json.get(jsonName, "x")], 5 is returned.



JSON_Objects are basically a way of storing multiple variables, by name, in a single variable. This makes your variables easier to organise, and easier to perform other functions on, e.g. searching for a particular value, or sorting. Use them, or use string property lists. Both achieve the same value, but the JSON structure has a few additional functions that string property lists do not have, I recommend them for both new and old coders.

If using json objects to store and organise sensible groups of your variables is like using trucks to transport coal from your mine to power plants in organised, weighed shipments, then your idea is like hiring a thousand men to carry a piece of coal each, and telling them walk to the power plants.

We aren't all telling you to use them because we're sadists. We're telling you to use them unless you're a masochist.

libavf
Cave Troll
Posts: 26
Joined: Fri Jan 18, 2013 2:48 pm

Re: Setting, Finding, and Rolling Skills/Stats with an Searc

Post by libavf »

I guess I am not sure in how to start using them. Do I set up one property that the json is linked to? Is it stored somewhere on the token automatically? Or is there something else I have to set up to use it in the first place?

Sorry if this seems too simple, but I have avoided any form of non-surface coding for a LOOOOOONG time.

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

Re: Setting, Finding, and Rolling Skills/Stats with an Searc

Post by wolph42 »

also see my earlier post on json as im not gonna explain it more.

lets assume the property on a token 'Skills'

Then a macro where you create the json object and assign it to that property (add [] yourself):

Code: Select all

jsonSkills = json.set("{}", "Swimming", 5, "Climbing","6")
setProperty("Skills", jsonSkills) 
thats it.

create dynamically:

Code: Select all

input("skillList|<enter CSV list of skill here>|Give list of Skills")
jsonSkills = "{}"
foreach(skill, skillList):jsonSkills = json.set(jsonSkills, skill, 0)
setProperty.... 
or

Code: Select all

input("skillList|<enter CSV list of skill here>|Give list of Skills")
jsonSkills = "{}"
foreach(skill, skillList),CODE:{
    input("value|0|Enter value for: "+skill)
    jsonSkills = json.set(jsonSkills, skill, value)
}

setProperty.... 

Ditto
Giant
Posts: 179
Joined: Thu Jul 28, 2011 1:06 pm

Re: Setting, Finding, and Rolling Skills/Stats with an Searc

Post by Ditto »

Rather than storing skills in the structure:

Code: Select all

Ride              5
Hide              4
Craft Skills      Books    3
                  Pots     4
Sneak             2
Which is, rather "awkward" to code "generically". (is it a group? or a skill? I need to check something "special" )

What about a more "generic" approach of:

Code: Select all

Group          Skill       Value
And you end up with:

Code: Select all

Standard          Ride     5
Standard          Hide     4
Standard          Sneak    2
Craft             Books    3
Craft             Pots     4
This results in the following json arrays:

As mentioned, first the "specifics:" (obviously this would be in some loop, but I've written it out by hand so you can see the step-by-step logic)

Code: Select all

[h: parent = ""]

-- work on Standard set
[h: child = "" ]
[h: child = json.set ( child, "ride", 5 ) ]
[h: child = json.set ( child, "hide", 4 ) ]
[h: child = json.set ( child, "sneak", 2 ) ]

[h: parent = json.set ( parent, "Standard", child )]

-- work on specific sets next
[h: child = "" ]
[h: child = json.set ( child, "books", 3 ) ]
[h: child = json.set ( child, "pots", 4 ) ]

[h: parent = json.set ( parent, "Craft Skills", child ) ]

-- lather, rinse repeat for as many "groups" as you have.

[h: Skills = parent ]
====================

To retrieve them ...

Code: Select all

[h: GroupName = "Standard" ]
[h: SkillName = "sneak" ]

[h: Group = json.get ( Skills, GroupName ) ]
[h: SkillValue = json.get ( Group, SkillName ) ]
==================

Is that dynamic enough for you? ;)

Post Reply

Return to “Macros”