input() and other new b42 macro functions

Doc requests, organization, and submissions

Moderators: dorpond, trevor, Azhrei

Post Reply
User avatar
Pyroman
Cave Troll
Posts: 68
Joined: Wed Dec 26, 2007 12:42 pm
Location: Tampa, FL

Post by Pyroman »

knizia.fan wrote:
BigO wrote:It's counter-intuitive to me to have abort(0) be the thing that stops the execution. If you're naming it 'abort' then the inherent question asked by calling the function is "Do you want to abort?" and by normal Boolean logic, an answer of zero means "No" or in this case "No, I don't want to abort". But that's the opposite of what it does.
I definitely understand what you're saying, and I had thought about it as well. The main use of abort() at the moment is to halt execution when the user clicks Cancel in an input dialog box. It made sense for the input() function to return 0 for Cancel (i.e. failure) and 1 for OK (i.e. success). It's important that people be able to use this value without modification in a call to abort(), so I made 0 cause the abort to happen.

I agree that it can seem odd, and if others also feel it should be changed, this could be tweaked in a later build. However, changing abort() means also changing the meaning of the return value for input() so that a 1 means failure and a 0 means success.

The current behavior can be thought of as "abort(success_code)", where the abort happens when success_code indicates a failure (i.e. it is 0).
You could simply rename this function 'continue()', or something similar. The functionality remains the same, but it would be more intuitive.

A big thank you knizia.fan for giving me the functionality that I didn't realize I needed until you slapped me in the face with it. :D

User avatar
palmer
Great Wyrm
Posts: 1367
Joined: Sat Sep 06, 2008 7:54 pm

Post by palmer »

FREQ: List sorting
(prompted by this post)

Some kind of list manipulation functionality to automatically sort a list. Basic numerical or character code sorts, in forward or reverse.

It would certainly help for the thread above, and I'm sure that others will have uses for it.

User avatar
PyroMancer2k
Dragon
Posts: 925
Joined: Thu Sep 11, 2008 2:04 pm

Post by PyroMancer2k »

Can you somehow use dynamic naming on the left side of the = sign? What I mean by that is you have things like eval("Weapon" + roll.count) which is very helpful in the weapon code for the Weapon1, Weapon2, and .... but what is I say want to set them via.

Weapon1= *****
Weapon2= *****

Is there a way I can set that up via something like:
eval("Weapon" + WpnNum) = ******

The reason is I got a list of properties and some of them are Yes/No properties and I might even have Radio choices down the road. But I don't want the player simply entering numbers in there cause I plan to use those for checks in formula and if player enter something other then a 1 or 0 it will mess it up. Plus it looks nice on the prompt.

I used your weapon edit code as basis and was able to extract the property so it doesn't show up on the prompt but assigned a new variable it and had a check box reference that variable. Now that it's done the trouble is getting that value back into the final result.

The problem is in your weapon edit code you referred to the variable Weapon1, Weapon2, and etc via the name stored in that over variable. So all the other props go in there. The trouble is I don't know how to make reference to that Weapon# in order to add the "getStrProp()". Is there some work around for this?

Syne
Kobold
Posts: 17
Joined: Fri Sep 19, 2008 9:15 am

Post by Syne »

I think I understand your question. Yes, you can do that, like this:

Code: Select all

[C(Iterations): eval ("Weapon" + roll.count + " = [varname]")]
Remember that eval() runs the contents of the string as code, so to the praser it will look like multiple iterations of Weapon# = [varname]. Note that the quotes contain the right part of the equation as well.
Though depending on the information you want stored, it might be better to use a list. No need to resort to eval().

Also, I want to thank the developers for this awesome addition. It really adds functionality.

It would be great if you had a possibility of choosing another delimiter for list, though. *thinks* and making lists/property strings from variables.

Lindharin
Dragon
Posts: 668
Joined: Sat Apr 21, 2007 4:51 pm

Post by Lindharin »

palmer wrote:FREQ: List sorting
(prompted by this post)

Some kind of list manipulation functionality to automatically sort a list. Basic numerical or character code sorts, in forward or reverse.

It would certainly help for the thread above, and I'm sure that others will have uses for it.
If someone tries to implement this request, you might consider having the sort function pad any numbers with some leading zeroes, so that Weapon2 comes out less than Weapon10, even though in a strict alphabetic sort it's the opposite.

I have some code that does the padding already in the sorting for global/campaign macros, which you could grab for this too.

User avatar
BigO
Dragon
Posts: 558
Joined: Mon Jul 28, 2008 12:23 pm
Location: Oshkosh, WI
Contact:

Post by BigO »

Syne wrote:I think I understand your question. Yes, you can do that, like this:

Code: Select all

[C(Iterations): eval ("Weapon" + roll.count + " = [varname]")]
Remember that eval() runs the contents of the string as code, so to the praser it will look like multiple iterations of Weapon# = [varname]. Note that the quotes contain the right part of the equation as well.
Though depending on the information you want stored, it might be better to use a list. No need to resort to eval().

Also, I want to thank the developers for this awesome addition. It really adds functionality.

It would be great if you had a possibility of choosing another delimiter for list, though. *thinks* and making lists/property strings from variables.
Your first post, and you already have a solid understanding of macro syntax? You must have been lurking for a while :)

Welcome to the boards!
--O

I am a small and fragile flower.
http://maptool.rocks.andyousuck.com

Syne
Kobold
Posts: 17
Joined: Fri Sep 19, 2008 9:15 am

Post by Syne »

Thanks :P.
Yeah, I've lurked here a couple of days. Most of my knowledge comes from playing around with it, though. I take sick pleasure in experimenting with simplistic and occasionally frustrating programming languages that have no debugging tools available.

Come to think of it, I think list sorting is possible with the current functions... at least numerical sorting. It would probably require some severe multi-statement eval() abuse, though. What's the deal with that, really? Why can't you make multiple statements with a calculation? With the loop type calculation, it would be extremely useful.

User avatar
Orchard
Great Wyrm
Posts: 1852
Joined: Fri May 09, 2008 10:45 am
Location: Doylestown PA
Contact:

Post by Orchard »

Syne wrote:Thanks :P.
Yeah, I've lurked here a couple of days. Most of my knowledge comes from playing around with it, though. I take sick pleasure in experimenting with simplistic and occasionally frustrating programming languages that have no debugging tools available.

Come to think of it, I think list sorting is possible with the current functions... at least numerical sorting. It would probably require some severe multi-statement eval() abuse, though. What's the deal with that, really? Why can't you make multiple statements with a calculation? With the loop type calculation, it would be extremely useful.
As the resident man with a degree in psychology, let me just say this bluntly--there's no cure for your breed of insanity, but even though I'm not licensed as a therapist (and never will be--I'm a researcher) I'll still gladly charge you lots of money to try and fix your problem, as you obviously are a sick and deranged person who needs someone to charge you lots of money. I can't help but think that this would make your life better. It would certainly make my life better, and as long as one of us is happier, something must be going right.

Oh, and welcome to the boards--we need more twisted folk who enjoy abusing the tools that trevor and company keep foisting upon us. :twisted: :twisted: :twisted:
0+0=1, for very unstable CPUs.

User avatar
BigO
Dragon
Posts: 558
Joined: Mon Jul 28, 2008 12:23 pm
Location: Oshkosh, WI
Contact:

Post by BigO »

Syne wrote:Thanks :P.
Yeah, I've lurked here a couple of days. Most of my knowledge comes from playing around with it, though. I take sick pleasure in experimenting with simplistic and occasionally frustrating programming languages that have no debugging tools available.
Well, you're in the right place.
Syne wrote:Come to think of it, I think list sorting is possible with the current functions... at least numerical sorting. It would probably require some severe multi-statement eval() abuse, though. What's the deal with that, really? Why can't you make multiple statements with a calculation? With the loop type calculation, it would be extremely useful.
I think it's mainly because it's all so new. The loop feature has only been around a couple of weeks. In the last couple of months the macro stuff has been getting a LOT of work. New features are getting added all the time and older syntax is getting fleshed out. It really feels like we're working together on creating a new language, which of course, some people like and some people don't. There's been some pretty heated threads on the topic.

Fortunately things are winding down now since we are getting really close to having external scripting support. Then all the more advanced stuff will be implemented there.
--O

I am a small and fragile flower.
http://maptool.rocks.andyousuck.com

User avatar
BigO
Dragon
Posts: 558
Joined: Mon Jul 28, 2008 12:23 pm
Location: Oshkosh, WI
Contact:

Post by BigO »

Orchard wrote:As the resident man with a degree in psychology, let me just say this bluntly--there's no cure for your breed of insanity
Syne, in case you missed it, he was paying you a complement.

But count yourself lucky. He's my DM!
--O

I am a small and fragile flower.
http://maptool.rocks.andyousuck.com

User avatar
Orchard
Great Wyrm
Posts: 1852
Joined: Fri May 09, 2008 10:45 am
Location: Doylestown PA
Contact:

Post by Orchard »

BigO wrote:
Orchard wrote:As the resident man with a degree in psychology, let me just say this bluntly--there's no cure for your breed of insanity
Syne, in case you missed it, he was paying you a complement.

But count yourself lucky. He's my DM!
Hey, careful there, we've got a gaming session coming up soon...

wouldn't want anything to happen to that character of yours.... :twisted:
0+0=1, for very unstable CPUs.

User avatar
PyroMancer2k
Dragon
Posts: 925
Joined: Thu Sep 11, 2008 2:04 pm

Post by PyroMancer2k »

BigO wrote:
Syne wrote:I think I understand your question. Yes, you can do that, like this:

Code: Select all

[C(Iterations): eval ("Weapon" + roll.count + " = [varname]")]
Remember that eval() runs the contents of the string as code, so to the praser it will look like multiple iterations of Weapon# = [varname]. Note that the quotes contain the right part of the equation as well.
Though depending on the information you want stored, it might be better to use a list. No need to resort to eval().

Also, I want to thank the developers for this awesome addition. It really adds functionality.

It would be great if you had a possibility of choosing another delimiter for list, though. *thinks* and making lists/property strings from variables.
Your first post, and you already have a solid understanding of macro syntax? You must have been lurking for a while :)

Welcome to the boards!
Actually his syntax is wrong. You can't have [] inside another []. But if you remove them it works fine ;).

Also what I was trying to do I only needed to do once so loop doesn't really help. But his eval() setup made me realize what I was doing wrong. I was trying to do something like:

Code: Select all

[h:eval("Armor" + ArmNum) = ...... ]
Problem was it kept eval the first part and didn't put Armor# = to what I was trying to set. Combine that with the fact I had to have some " " marks in there for other functions. I did however realize that I needed to put it all under 1 eval and once I got the " and ' order sorted it worked fine. The end result was this line of the code:

Code: Select all

[H:eval ('Armor' + ArmNum + ' = setStrProp(eval("Armor" + ArmNum), "IsLight", ArmLight)'))] 
The full macro is just like K.fan weapon editor except it only does 3 armors and there is a check box for if the armor is Light rather then having the player enter a value. Here is the finished working code:

Code: Select all

---Variables Needed
Armor1:Name=Cloth ; ArmorBonus=0 ; EnchantBonus=0 ; CheckPenalty=0; SpeedPenalty=0 ; Notes/Powers=None ; Keyword=None ; IsLight=1 ;
Armor2:Name=Hide ; ArmorBonus=5 ; EnchantBonus=0 ; CheckPenalty=1; SpeedPenalty=0 ; Notes/Powers=None ; Keyword=None ; IsLight=1 ;
Armor3:Name=Plate ; ArmorBonus=8 ; EnchantBonus=0 ; CheckPenalty=2; SpeedPenalty=1 ; Notes/Powers=None ; Keyword=None ; IsLight=0 ;



---Armor Setup v2
  [h: ArmList = ""]
  [h, c(3,""): ArmList = ArmList + getStrProp(eval("Armor" + roll.count), "Name") + ","]

  [h: fail = input("ArmNum | " + ArmList + " | Select Armor to edit | LIST")]
  [h: abort(fail)]
  [h: ArmNum = ArmNum + 1]
  [h: ArmName = "Armor" + ArmNum]
  [h: ArmProps = eval(ArmName)]
  [h:ArmLight = getStrProp(ArmProps, "IsLight")]<BR>
  [h: ArmProps = deleteStrProp(ArmProps, "IsLight")]
 
  [h: NumProps = countStrProp(eval(ArmName))]
  [h: abort(NumProps)]
 
  [h: fail = input("blah | " + ArmNum + " | Armor number | LABEL",
      " ArmLight | "+eval('ArmLight')+" | This is Light Armor | CHECK",
      ArmName + " | " + ArmProps + " | Armor properties | PROPS | setvars=true")]
  [h: abort(fail)]

[H:eval ('Armor' + ArmNum + ' = setStrProp(eval("Armor" + ArmNum), "IsLight", ArmLight)'))] 

New properties for armor #{ArmNum}:
<table border=0>
[h: NumProps = countStrProp(eval(ArmName)) - 1]
[h,p,c(NumProps,""):
    "<tr><td style='padding:0px 5px'><b>"
    + indexKeyStrProp(ArmProps,roll.count-1)
    + "</b></td><td>"
    + eval(indexKeyStrProp(ArmProps,roll.count-1))
    + "</td></tr>" ]
</table>


Thanks for the help.

User avatar
PyroMancer2k
Dragon
Posts: 925
Joined: Thu Sep 11, 2008 2:04 pm

Post by PyroMancer2k »

LOL New problem. Different bit of code this time around. I want to have a prompt and based on the users choice another prompt pops up.

I tried something along the lines of:

Code: Select all

[h: input("MenuItem | ....)]

Which player picks one of 3 choices. Then I have check.

[h: if(MenuItem == 0, input(NewPrompt), ""]
[h: if(MenuItem == 1, input(NewPrompt), ""]
[h: if(MenuItem == 2, input(NewPrompt), ""]
I know the syntax is a little off but it's just an example cause the code I have works with one small hitch. The other input boxes put up no matter what. From what I can tell input always pop up even if they are part of an if statement.

Is there any way to correct this or do input boxes always have to pop up?

Syne
Kobold
Posts: 17
Joined: Fri Sep 19, 2008 9:15 am

Post by Syne »

Yeah, I tried to imply that you don't write 'varname' in the quotes but that instead you should write your variable. That's how I usually do it when discussing code. Wasn't clear, unfortunately, given the syntax.

Yeah, that indeed seems to be the case, and I think this would constitute a bug. What you can do is make an if that retrieves the code line that calls up input or a meaningless expression, and then eval() the return.
Meaningless but parsable, I mean.
Last edited by Syne on Fri Sep 19, 2008 3:59 pm, edited 1 time in total.

User avatar
Pyroman
Cave Troll
Posts: 68
Joined: Wed Dec 26, 2007 12:42 pm
Location: Tampa, FL

Post by Pyroman »

I cannot get any input boxes to pop up. I tried to just enter:

Code: Select all

[input()]
and I get an error "Could not execute the command: Invalid number of parameters 0, expected at least 1 parameters" which I would expect.
I enter the following into the chat parser:

Code: Select all

[input("test")]
and nothing happens. It is as if I cannot press enter. The text just stays in the chat input window and nothing happens. If I then delete the end brace so that it is no longer a legal command and press enter, it goes to the chat as text.

So the chat parser is recognizing the command but not executing it. Anyone else experience this? I am using 1.3.b43.

Post Reply

Return to “Documentation Requests/Discussion”