Post Reply 
Mixing input and output in a Prime program
09-22-2024, 10:25 PM (This post was last modified: 09-22-2024 10:25 PM by CheshireChris.)
Post: #1
Mixing input and output in a Prime program
I'm trying to get my head around the basic ideas of Prime programming in PPL, and there's one thing I'd appreciate some assistance with.

In a typical "command line/terminal" program you might want to display some information to the user, prompt for an input, and then display some further information as a result To use a trivial example of a card game, something like:

Your cards are 5 7 J K A
How much do you want to bet?

And then wait for the user to type in a number.

On the Prime, information output with a "PRINT" command goes to a terminal
screen, but when you prompt for an input, this is done on a separate "input" screen and the terminal is hidden. How can you display information to the user and then prompt for an input with that information still visible?

Chris
Find all posts by this user
Quote this message in a reply
09-23-2024, 01:34 AM
Post: #2
RE: Mixing input and output in a Prime program
You can put Your cards are 5 7 J K A in the title of the input window.
Find all posts by this user
Quote this message in a reply
09-23-2024, 05:02 AM (This post was last modified: 09-23-2024 05:02 AM by komame.)
Post: #3
RE: Mixing input and output in a Prime program
(09-22-2024 10:25 PM)CheshireChris Wrote:  On the Prime, information output with a "PRINT" command goes to a terminal
screen, but when you prompt for an input, this is done on a separate "input" screen and the terminal is hidden. How can you display information to the user and then prompt for an input with that information still visible?

Besides the INPUT command, there is also the READLINE command, which allows the user to input in a separate line at the very bottom of the terminal screen. This way, the terminal is not hidden.

Code:
EXPORT USERINPUT()
BEGIN
  LOCAL bet;
  PRINT("How much do you want to bet?");
  bet:=READLINE();
  PRINT("You have bet " + bet);
END;

The READLINE command returns a string, so in your case, you need to convert the input to an integer.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
09-23-2024, 06:03 AM
Post: #4
RE: Mixing input and output in a Prime program
(09-23-2024 05:02 AM)komame Wrote:  Besides the INPUT command, there is also the READLINE command, which allows the user to input in a separate line at the very bottom of the terminal screen. This way, the terminal is not hidden.

Code:
EXPORT USERINPUT()
BEGIN
  LOCAL bet;
  PRINT("How much do you want to bet?");
  bet:=READLINE();
  PRINT("You have bet " + bet);
END;

The READLINE command returns a string, so in your case, you need to convert the input to an integer.

Perfect! Thank you - this is exactly what I was looking for.

Chris
Find all posts by this user
Quote this message in a reply
09-23-2024, 11:56 AM
Post: #5
RE: Mixing input and output in a Prime program
(09-23-2024 05:02 AM)komame Wrote:  The READLINE command returns a string, so in your case, you need to convert the input to an integer.

Another very simple question: the only type conversion function I can find in PPL is "EXPR". Is this the correct function to use to convert a string to a number?

Something like:

Code:

LOCAL a,b;
a:=READLINE(); // a is a string
b:=EXPR(a); // b is now a number?

Chris
Find all posts by this user
Quote this message in a reply
09-23-2024, 05:49 PM
Post: #6
RE: Mixing input and output in a Prime program
Bonjour
Oui c'est bien la fonction EXPR qu'il faut utiliser.
Attention EXPR fonctionnera seulement si vôtre entrée est une valeur uniquement :
EXPR("128.5") --> 128.5
EXPR("128.5$") --> erreur
Contrairement à VAL( des anciens Basics .

Hello
Yes, you need to use the EXPR function.
EXPR will only work if your input is a value:
EXPR("128.5") --> 128.5
EXPR("128.5$") --> error
Unlike VAL( in the old Basics .

Sorry for my english
Find all posts by this user
Quote this message in a reply
09-23-2024, 05:53 PM
Post: #7
RE: Mixing input and output in a Prime program
(09-23-2024 05:49 PM)Tyann Wrote:  Hello
Yes, you need to use the EXPR function.
EXPR will only work if your input is a value:
EXPR("128.5") --> 128.5
EXPR("128.5$") --> error
Unlike VAL( in the old Basics .

Merci, Tyann!

Chris
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 4 Guest(s)