On 07 Dec 2021, 07:49p, fang-castro said the following...
I'm going through Black Panther's MPL tutorials and just wondering if
some of this stuff is keeping people from trying to learn MPL. My guess
Thanks for taking a look at those. They have been fun to write as well. :)
is MPL has changed since the tutorials were written. I kind of enjoy the subtle 'bugs' I run into and don't get me wrong, I'm not knocking BP - thank you for the tutorials! Here's what I was able to figure out on
this first lession.
These were written within the last 6 months or so. There have been some minor changes.
The USES command needs to preceed each "uses".
Not necessarily.
Uses
Cfg,
User
... is just as valid as
Uses Cfg
Uses User
Each of the uses must be separated by a comma.
The "Byte" vartype doesn't work with "Input(#,#,#,'')" I was getting type mismatch errors with the compiler. I just changed it to string for now instead of trying to figure out how "Byte" works.
Input will only take a string from the user. Once the input is obtained, it can be typecast to a different variable type. So, if you have something like:
Var
UserInput : String;
UserByte : Byte;
Begin
UserInput:=Input(2,2,10,'');
UserByte:=Str2Int(UserInput);
End
You can do something like this to change it to a byte. Be careful though if you are using Input which would accept all characters, such as input type 1. If you try to change an string to any integer type variable, and it contains non-numeric characters, it will crash. I usually put in some type of check function in the program, to determine if it contains all numeric, before attempting the Str2Int.
The first snippet is the original code from Tutorial 1 and the second snippet is what I changed it to so it would compile.
Did I have that in the first tutorial? I'll have to take a look at what I wrote... Oh crap... Sorry about that... Yes, the Age variable would need to be a string in that example... Another way of doing it would be:
Uses
User,
CFG
Var
Age : Byte
Name : String[20]
Begin
WriteLn('What is your name?')
Name:=Input(20,20,3,'')
WriteLn('Hi '+Name+'! How old are you?')
Age:=Str2Int(Input(2,2,10,''))
WriteLn(Name+' are you really only '+Int2Str(Age)+' years old?')
End
This is untested, but it should work.
I guess I should go back and proofread what I wrote in those tutorials... ;)
---
Black Panther(RCS)
aka Dan Richter
Castle Rock BBS
telnet://bbs.castlerockbbs.com
http://www.castlerockbbs.com
http://github.com/DRPanther
The sparrows are flying again...
... They say there's always one weirdo on the bus, but I couldn't find them!
--- Mystic BBS v1.12 A47 2021/09/07 (Linux/64)
* Origin: Castle Rock BBS - bbs.castlerockbbs.com (21:1/186)