Get 8 different results (1-8) mixed

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

Post Reply
oblisgr
Giant
Posts: 132
Joined: Mon Aug 01, 2011 6:43 am
Location: Crete,Greece
Contact:

Get 8 different results (1-8) mixed

Post by oblisgr »

Hello,
I need to make a makro that will give 8 results from 1-8 mixed and add them to the assigned token properties.
Can anyone help?
Last edited by oblisgr on Sun Sep 10, 2017 5:15 pm, edited 1 time in total.
High Templar of Ur


oblisgr
Giant
Posts: 132
Joined: Mon Aug 01, 2011 6:43 am
Location: Crete,Greece
Contact:

Re: Get 8 different results (1-8) scrumbled

Post by oblisgr »

mixed i meant. :lol:
High Templar of Ur

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Get 8 different results (1-8) mixed

Post by aliasmask »

It's kind of vague, but here's one way.

Code: Select all

<!-- have a list with numbers in it -->
[H: myList = "1,2,4,8,12,16,20,24"]

<!-- pick a random number from list -->
[H: pick = listGet(myList,1d8-1)]

<!-- get existing value on token -->
[H: tokenProp = getProperty("myProp")]

<!-- if its empty, set to 0 -->
[H, if(json.isEmpty(tokenProp)): tokenProp = 0]

<!-- add the values together -->
[H: tokenProp = tokenProp + pick]

<!-- save total on token -->
[H: setProperty("myProp",tokenProp)] 

oblisgr
Giant
Posts: 132
Joined: Mon Aug 01, 2011 6:43 am
Location: Crete,Greece
Contact:

Re: Get 8 different results (1-8) mixed

Post by oblisgr »

aliasmask wrote:It's kind of vague, but here's one way.

Code: Select all

<!-- have a list with numbers in it -->
[H: myList = "1,2,4,8,12,16,20,24"]

<!-- pick a random number from list -->
[H: pick = listGet(myList,1d8-1)]

<!-- get existing value on token -->
[H: tokenProp = getProperty("myProp")]

<!-- if its empty, set to 0 -->
[H, if(json.isEmpty(tokenProp)): tokenProp = 0]

<!-- add the values together -->
[H: tokenProp = tokenProp + pick]

<!-- save total on token -->
[H: setProperty("myProp",tokenProp)] 
I dont understand how it gives 8 different results taken from the list.
If the list = 1,2,3,4,5,6,7,8 I want it to give 8 results from 1 to 8 non repeatable with random place.
Thats the thing
High Templar of Ur

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Get 8 different results (1-8) mixed

Post by aliasmask »

I think you need to give a more detailed example then, because I'm not understanding what you're trying to accomplish.

oblisgr
Giant
Posts: 132
Joined: Mon Aug 01, 2011 6:43 am
Location: Crete,Greece
Contact:

Re: Get 8 different results (1-8) mixed

Post by oblisgr »

[H: myList = "1,2,3,4,5,6,7,8"]

[H: pick1 = listGet(myList,1d8-1)]
[H: pick2 = listGet(myList,1d8-1)]
[H: pick3 = listGet(myList,1d8-1)]
[H: pick4 = listGet(myList,1d8-1)]
[H: pick5 = listGet(myList,1d8-1)]
[H: pick6 = listGet(myList,1d8-1)]
[H: pick7 = listGet(myList,1d8-1)]
[H: pick8 = listGet(myList,1d8-1)]

[r:pick1][r:pick2][r:pick3][r:pick4][r:pick5][r:pick6][r:pick7][r:pick7][r:pick8]

Run this 3 times, gave me the following results:

611163777
436452441
461343777

The thing i dont want on these results are the repeatable results.
For example in first result i get 2x6,3x1,3x7 while i would like to get something like 13478265 (no number is repating)
High Templar of Ur

jacktim
Kobold
Posts: 2
Joined: Mon Apr 16, 2012 9:23 pm

Re: Get 8 different results (1-8) mixed

Post by jacktim »

The OP is asking for it to distribute the numbers 1-8 once each into an output.
Examples: 12345678, 13827465, 81726354, ... and so on, so that each call gives a random ordered list of the numbers 1-8.

Code: Select all

[h: myList = json.fromList("1,2,3,4,5,6,7,8")] <!-- list of 1 to 8 -->
[h: myVal = ""] <!-- Blank val to set -->

<!-- Repeat until no items left -->
[h, WHILE(json.length(myList) > 0), CODE:
{
[h: choose = d(1,json.length(myList))-1] <!-- Pick one-->
[h: myVal = myVal + string(json.get(myList, choose))] <!-- Add it to the value -->
[h: myList = json.remove(myList, choose)] <!-- Remove it from the list, prevents repeats -->
}]

<!-- save output on token -->
[H: setProperty("myProp", myVal)] 

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Get 8 different results (1-8) mixed

Post by aliasmask »

Ah, that's an easy one then.

Code: Select all

[H: myList = json.append("",1,2,3,4,5,6,7,8)]
[H: newList = json.shuffle(myList)]
[R: json.toList(newList,"")]

oblisgr
Giant
Posts: 132
Joined: Mon Aug 01, 2011 6:43 am
Location: Crete,Greece
Contact:

Re: Get 8 different results (1-8) mixed

Post by oblisgr »

I made this code that gives me the result i need. The only problem is that the 1st and the 8th number appear with [ and ].
I dont know why.

[H: myList = json.append(1,2,3,4,5,6,7,8)]
[H: newList = json.shuffle(myList)]

[r: pick1 = listGet(newlist, 0)]
[r: pick2 = listGet(newlist, 1)]
[r: pick3 = listGet(newlist, 2)]
[r: pick4 = listGet(newlist, 3)]
[r: pick5 = listGet(newlist, 4)]
[r: pick6 = listGet(newlist, 5)]
[r: pick7 = listGet(newlist, 6)]
[r: pick8 = listGet(newlist, 7)]

[H: setProperty("Melee", pick1)]
[H: setProperty("Range", pick2)]
[H: setProperty("Fire", pick3)]
[H: setProperty("Frost", pick4)]
[H: setProperty("Nature", pick5)]
[H: setProperty("Arcane", pick6)]
[H: setProperty("Holy", pick7)]
[H: setProperty("Shadow", pick8)]
High Templar of Ur

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Get 8 different results (1-8) mixed

Post by aliasmask »

Change listGet to json.get.

You can also do this:

Code: Select all

[H: attackTypes = json.fromList("Melee,Range,Fire,Frost,Nature,Arcane,Holy,Shadow")]
[H: randId = json.append("",1,2,3,4,5,6,7,8)]
[H: randId = json.shuffle(randId)]
[H, foreach(attackProp,attackTypes): setProperty(attackProp,json.get(randId,roll.count))]

oblisgr
Giant
Posts: 132
Joined: Mon Aug 01, 2011 6:43 am
Location: Crete,Greece
Contact:

Re: Get 8 different results (1-8) mixed

Post by oblisgr »

aliasmask wrote:Change listGet to json.get.

You can also do this:

Code: Select all

[H: attackTypes = json.fromList("Melee,Range,Fire,Frost,Nature,Arcane,Holy,Shadow")]
[H: randId = json.append("",1,2,3,4,5,6,7,8)]
[H: randId = json.shuffle(randId)]
[H, foreach(attackProp,attackTypes): setProperty(attackProp,json.get(randId,roll.count))]
I used the json.get and worked.
Thanks for help
High Templar of Ur

Post Reply

Return to “Macros”