zero's before an int
Hey folks,
I'm trying to send a coordinate msg to a telescope. The format should look something like this
#:Sz 026^07:05#
with sprintf i can insert the symbols, but then coordinates such as "026" or "07" get truncated to 26 or 7.
I need the zero's in front for the ascii command to work. If i used the coordinate as a string it still truncates the zero's, unless there's a non-numeric value in the string. (weird???)
So my work around was to simple add a non-numeric value with append which in theory should work, but doesn't....
It's quite the catch 22. Can anyone offer advise? This is making my headspin. thanks!! -jon
this sounds like a candidate for a simple javascript. use the [js]
object and write a script to format it for you. My programming chops
are terrible, but I've been able to use the js docs in max to write
enough java scripts in max to do things max is not good at (strings,
lists).
good luck.
On Dec 10, 2007, at 12:18 AM, spleenless wrote:
>
> Hey folks,
>
> I'm trying to send a coordinate msg to a telescope. The format
> should look something like this
> #:Sz 026^07:05#
>
> with sprintf i can insert the symbols, but then coordinates such as
> "026" or "07" get truncated to 26 or 7.
>
> I need the zero's in front for the ascii command to work. If i used
> the coordinate as a string it still truncates the zero's, unless
> there's a non-numeric value in the string. (weird???)
>
> So my work around was to simple add a non-numeric value with append
> which in theory should work, but doesn't....
>
> It's quite the catch 22. Can anyone offer advise? This is making my
> headspin. thanks!! -jon
>
>
>
> max v2;
> #N vpatcher 116 110 716 510;
> #P window setfont "Sans Serif" 9.;
> #P window linecount 1;
> #P message 81 253 92 196617 #:Sz 026^07:05#;
> #P newex 292 204 102 196617 sprintf %s %s: %s;
> #P newex 418 104 30 196617 t b b;
> #P message 396 165 20 196617 7;
> #P message 358 168 24 196617 ^06;
> #P button 418 66 15 0;
> #P message 292 168 38 196617 021;
> #N vpatcher 20 74 622 514;
> #P outlet 186 364 15 0;
> #P inlet 65 33 17 0;
> #P window setfont "Sans Serif" 9.;
> #P message 137 166 54 196617 separator;
> #P newex 186 313 51 196617 tosymbol;
> #P newex 186 338 62 196617 prepend set;
> #P message 208 363 82 196617 021;
> #P newex 213 199 43 196617 r digits;
> #P newex 50 76 43 196617 s digits;
> #P message 121 195 14 196617 1;
> #P button 188 124 15 0;
> #P toggle 99 195 15 0;
> #P number 106 263 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P user gswitch 106 220 41 32 1 0;
> #P newex 215 228 54 196617 prepend 0;
> #P newex 186 289 53 196617 switch 3;
> #P newex 200 253 63 196617 prepend 0 0;
> #P newex 207 95 76 196617 sprintf %ld 99;
> #P newex 207 122 156 196617 if $i1> $i2 then set 3 else set 2;
> #P newex 26 95 76 196617 sprintf %ld 10;
> #P number 26 34 35 9 0 360 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 207 159 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 26 161 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 26 123 156 196617 if $i1 < $i2 then set 0 else set 1;
> #P connect 21 0 4 0;
> #P connect 3 0 4 0;
> #P connect 4 0 0 0;
> #P connect 13 0 1 0;
> #P connect 0 0 1 0;
> #P connect 21 0 15 0;
> #P connect 3 0 15 0;
> #P connect 1 0 12 0;
> #P connect 12 0 10 0;
> #P connect 10 0 11 0;
> #P connect 1 0 14 0;
> #P connect 14 0 10 1;
> #P connect 2 0 10 2;
> #P connect 13 0 20 0;
> #P connect 11 0 8 0;
> #P connect 20 0 19 0;
> #P connect 8 0 19 0;
> #P connect 19 0 18 0;
> #P connect 18 0 22 0;
> #P connect 21 0 13 0;
> #P connect 3 0 13 0;
> #P connect 16 0 7 0;
> #P connect 7 0 8 1;
> #P connect 21 0 6 0;
> #P connect 3 0 6 0;
> #P connect 6 0 5 0;
> #P connect 13 0 2 0;
> #P connect 5 0 2 0;
> #P connect 18 0 17 0;
> #P connect 9 0 8 2;
> #P connect 16 0 9 0;
> #P connect 16 0 8 3;
> #P pop 1;
> #P newobj 289 110 49 196617 p 3digits;
> #P message 232 191 54 196617 separator;
> #P newex 284 264 51 196617 tosymbol;
> #P message 81 231 96 196617 #:Sz DDD^MM:SS#;
> #P number 289 87 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 284 289 62 196617 prepend set;
> #P message 284 315 111 196617 21^06:7;
> #P window linecount 2;
> #P comment 79 201 100 196617 what i need as the outcome;
> #P user panel 54 161 164 133;
> #X brgb 255 247 207;
> #X frgb 0 0 0;
> #X border 0;
> #X rounded 0;
> #X shadow 0;
> #X done;
> #P background;
> #P connect 10 0 7 0;
> #P connect 7 0 6 0;
> #P connect 14 0 6 0;
> #P connect 6 0 3 0;
> #P connect 3 0 2 0;
> #P connect 4 0 8 0;
> #P connect 13 1 9 0;
> #P connect 8 0 9 0;
> #P connect 9 0 14 0;
> #P connect 11 0 14 1;
> #P connect 13 0 11 0;
> #P connect 12 0 14 2;
> #P connect 13 0 12 0;
> #P connect 10 0 13 0;
> #P pop;
>
sprintf %03d^%02d:%02d
_
johan
can someone tell me why the following doesn't work?
sprintf %02d
it requires a character after the "d" to actually add the padded zeros.
Quote: robtherich wrote on Mon, 10 December 2007 11:12
----------------------------------------------------
> can someone tell me why the following doesn't work?
>
> sprintf %02d
>
> it requires a character after the "d" to actually add the padded zeros.
----------------------------------------------------
It does work, but...
Max transforms the output back to an int as soon as you do anything with it. If you want a symbol, you need the "symout" flag, like:
sprintf symout %02d
mz
thanks
wow so much more elegant then my if statements and multiple > symbols. thanks!!
The %02d works fine *if* it's combined with other stuff to sprintf something that Max will parse as a symbol. Something like [sprintf #:Sz %03d^%02d:%02d#] will spit out a symbol.
Hi list,
I'm looking for an alternative solution to waveform~ object. This one
is too buggy for me when restoring parameters (used in a plugin in
combination with pp).
Any idea for displaying efficiently a waveform using LCD?
Thank you very much,
Regards,
Eric L.
the combine object allows selective number padding, hence
combine "#:Sz " i ^ i : i d# @triggers 1 3 5 @padding 0 3 0 2 0 2 0
> #:Sz 026^07:05d# (fromsymbol)
when
26 is sent to inlet 1 (mth)
7 > 3
5 > 5
and the padding attribute 0 3 0 2 0 2 0 makes inlet 1 turn into a 3-digit-number with preceding zeros, 3 > 2-digit, 5 > 2-digit etc.
though this operates slightly differently to sprintf on negatives, as for the 'minus' symbol is part of the 3/2/2 setting, hence removes a zero.
yet the number of preceding zeros are still changeable for any incoming message as are the 'hot' inlets of the combine object.
just another way of doing things.