LoginLogin

Text-Only Loading Bar

Root / Submissions / [.]

12Me21Created:
A progress/loading bar, made from only text. It's accurate to the nearest pixel
DEF TEXTBAR LENGTH%
 PRINT ""*(LENGTH% DIV 8);
 IF LENGTH% MOD 8 THEN PRINT " "[LENGTH% MOD 8];
END
Draws a LENGTH% * 8(pixel) rectangle with text For loading on the top screen LENGTH% should be PROGRESS/MAXIMUM * 400

I'd recommend using the # suffix so it also works in programs that have OPTION DEFINT. EDIT: I'd also make the max length a parameter, so it can be used on the lower screen and as part of a line. And to answer your question, a variable named PERCENT should have a percent value. Perhaps you're looking for PROGRESS#.

Code gives syntax error. Use + for string concatenation. It would also be more useful if there wasn't a space character at the end of lengths that are multiples of 8.

Replying to:SquareFingers
I'd recommend using the # suffix so it also works in programs that have OPTION DEFINT. EDIT: I'd also make the max length a parameter, so it can be used on the lower screen and as part of a line. And to answer your question, a variable named PERCENT should have a percent value. Perhaps you're looking for PROGRESS#.
length is in pixels, so it doesn't really matter if it's an integer or not.

Replying to:SquareFingers
Code gives syntax error. Use + for string concatenation. It would also be more useful if there wasn't a space character at the end of lengths that are multiples of 8.
yeah, that was a typo as for the space at the end, I'll add *!!(LENGTH MOD 8) or something

Replying to:SquareFingers
Code gives syntax error. Use + for string concatenation. It would also be more useful if there wasn't a space character at the end of lengths that are multiples of 8.
The second string now appears to have only 7 characters: for the indexing to work, you need 8 characters in the string, including one for the condition L MOD 8 == 0, even though that character will be removed from the resulting string by *0. - I hope I do not annoy, I just want to see this code be the best it can be.

Replying to:SquareFingers
Code gives syntax error. Use + for string concatenation. It would also be more useful if there wasn't a space character at the end of lengths that are multiples of 8.
Yeah, another typo. thanks

woah, you can do string picking using array syntax? what is this wizardry?

Replying to:chicken
woah, you can do string picking using array syntax? what is this wizardry?
It's called not being terrible at programming Yeah, strings are kind of like arrays of characters, so you can use most array commands on them, like PUSH, POP, COPY, etc.

Replying to:chicken
woah, you can do string picking using array syntax? what is this wizardry?
D:

Replying to:SquareFingers
I'd recommend using the # suffix so it also works in programs that have OPTION DEFINT. EDIT: I'd also make the max length a parameter, so it can be used on the lower screen and as part of a line. And to answer your question, a variable named PERCENT should have a percent value. Perhaps you're looking for PROGRESS#.
(also function arguments ignore type suffixes)

Replying to:SquareFingers
I'd recommend using the # suffix so it also works in programs that have OPTION DEFINT. EDIT: I'd also make the max length a parameter, so it can be used on the lower screen and as part of a line. And to answer your question, a variable named PERCENT should have a percent value. Perhaps you're looking for PROGRESS#.
The code has changed since my comment, and it is true that in the current version of SmileBasic, variable suffixes on actual parameters are meaningless, but the recommendation remains that variable names - including suffix - are better more descriptive than less (until you run into excessive wordiness, which one extra symbol is not).

Replying to:SquareFingers
I'd recommend using the # suffix so it also works in programs that have OPTION DEFINT. EDIT: I'd also make the max length a parameter, so it can be used on the lower screen and as part of a line. And to answer your question, a variable named PERCENT should have a percent value. Perhaps you're looking for PROGRESS#.
I usually put type suffixes on function arguments (this function doesn't have them because I was bad at programming when I wrote it). But now that I think about it, using type suffixes here is actually kind of misleading, since it implies that SB will convert the passed values to the specified type. For example:
DEF EVEN(X#)
 X#=X#/2
 RETURN FLOOR(X#)==X#
END
It looks like it should work, but if you do EVEN(5) it will return TRUE. This is because X# is actually an integer in that case. (This won't stop me from using type suffixes, though.)