Page 1 of 1

How to print string variable?

Posted: Mon Mar 06, 2023 4:01 pm
by Mussel
I decided to give Craft Basic a try, this is my first app written in Craft Basic, but I don't know how to print string variable:

Code: Select all

input "Please enter you name", s
print "Welcome ", s
print s
It prints "0" instead of the input I typed. EDIT: I removed the "dim" command as it is for array declaration, and since "s" is already predefined.

Also, since there is input box, is there a message box? EDIT: I think I found it, "alert" function.

Thank you for the hard work!

Re: How to print string variable?

Posted: Mon Mar 06, 2023 6:40 pm
by admin
Hello, Mussel. Welcome and thank you for trying Craft Basic.

I have not added support for string variables yet. It's in the to-do list.

Currently, print, alert, title, and run commands may combine their outputs.

For example:

Code: Select all

input "How old are you?", age
alert "Hello", comma, " you are ", age, " years old.", newline, "Have a nice day!"
end
The keywords COMMA and NEWLINE may be used to add commas and newlines to your output.
Currently, there's no way to concatenate to and output a buffer of text.
Input prompts are limited to two lines of text.

Re: How to print string variable?

Posted: Wed Mar 08, 2023 7:12 pm
by Mussel
Oh, I see, once you have implemented the string variable, I guess I want build a program with recursion to print all combination of letters in certain length

For example I mean with 'A,B,C" all the possible combination in 5 characters.

Code: Select all

A,A,A,A,A
A,A,A,A,B
A,A,A,A,C
A,A,A,B,B
A,A,A,B,C
A,A,A,C,C
A,A,B,B,B
A,A,B,B,C
A,A,B,C,C
A,A,C,C,C
A,B,B,B,B
A,B,B,B,C
A,B,B,C,C
A,B,C,C,C
A,C,C,C,C
B,B,B,B,B
B,B,B,B,C
B,B,B,C,C
B,B,C,C,C
B,C,C,C,C
C,C,C,C,C
I suggest you can also make this as your example code if you don't have one.
As for me, its algorithm to generate it is still unknown to me.

Re: How to print string variable?

Posted: Wed Mar 08, 2023 9:00 pm
by admin
Ok, I will note this as a design goal. It seems like a perfect way to test the language.

The only recursion Craft Basic supports is calling a sub from the same sub, creating a loop. Simple stuff. Subs don't accept parameters and all variable data is global.