Login / Register  0 items | $0.00 NewWhat is KVR? Submit News Advertise

Long script on K4

hellishvictor
KVRist
 
80 posts since 29 Apr, 2008

Postby hellishvictor; Wed Aug 09, 2017 7:45 am Long script on K4

Hi everybody

Is there a way to short the following cases with a "WHILE" or something (like with a IF and $count := $count +8), because the script I'm working now is getting very loooong...

Code: Select all
select ($test)
   case 0
      %whatever[$count] := $something
   case 1
      %whatever[$count +8] := $something
   case 2
      %whatever[$count +16] := $something
   case 3
      %whatever[$count +24] := $something
   case 4
      %whatever[$count +32] := $something
   case 5
      %whatever[$count +40] := $something
   (and it continues until case 127)
end select


Thanks
User avatar
whyterabbyt
Beware the Quoth
 
24955 posts since 3 Sep, 2001, from R'lyeh Oceanic Amusement Park and Funfair

Postby whyterabbyt; Wed Aug 09, 2017 7:53 am Re: Long script on K4

From that example; put it in a lookup table?

%whatever[$count + lookuptable[case]] := $something
"The bearer of this signature is a genuine and authorised pope."
Armagibbon
KVRist
 
409 posts since 20 Apr, 2017

Postby Armagibbon; Wed Aug 09, 2017 9:18 am Re: Long script on K4

Never did kontakt script stuff so I dunno this syntax but if you're trying to set values in a table based on some test you did...
Code: Select all
%whatever[$count + ($test*8)] := $something

But that's if $test is some acceptable type for the array. And I guess if there's no way to do inline typecast you prolly gotta make sure $test and $count are the same type before you try that... got no f*ckin clue about any of that in kontakt scripts sorry. Now you might wanna avoid switch cases unless you got a ton of unique cases. Iterating numbers up like that? Just throw the value into your array there. But make sure you won't go out of range cus you're gonna hate what happens, so check validity and all that first. It'd be something like...
Code: Select all
{somewhere you declare whatever...}
declare $WHATEVER_MAX := 128 {...or whatever %whatever's size is supposed to be}
declare %whatever[$WHATEVER_MAX]
{...}
declare $i := ($test*8) + $count
if ($i > ($WHATEVER_MAX - 1))
   $i := ($WHATEVER_MAX - 1)
end if
%whatever[$i] := $something
Last edited by Armagibbon on Wed Aug 09, 2017 1:07 pm, edited 6 times in total.
User avatar
EvilDragon
KVRAF
 
14546 posts since 6 Jan, 2009, from Croatia

Postby EvilDragon; Wed Aug 09, 2017 9:19 am Re: Long script on K4

Yeah, it would be what Armagibbon wrote.

BTW Armagibbon, they are the same type. $ denotes integer variable in KSP.

Also I assume this is being done in a while loop (that's what $count variable implies, sort of), so as long as boundary for the while loop is set properly, there shouldn't be array overflow.
Armagibbon
KVRist
 
409 posts since 20 Apr, 2017

Postby Armagibbon; Wed Aug 09, 2017 9:22 am Re: Long script on K4

Makes sense. Might wanna use a uint type or something for counting and all that... I gotta learn this shit man. Is the nils tutorial a good place for starters?
User avatar
EvilDragon
KVRAF
 
14546 posts since 6 Jan, 2009, from Croatia

Postby EvilDragon; Wed Aug 09, 2017 9:23 am Re: Long script on K4

KSP reference is good for starters (PDF comes installed with Kontakt).

KSP doesn't have unsigned ints. :P Just 31-bit signed ints ($), int arrays, same 31-bit signed (%), strings (@), string arrays (!), floats (~) and float arrays (?). The last two only from version 5.6 onward.
Armagibbon
KVRist
 
409 posts since 20 Apr, 2017

Postby Armagibbon; Wed Aug 09, 2017 9:27 am Re: Long script on K4

Kickass thanks! Had no idea about the official docs... gonna learn me some ksp now hahaha
hellishvictor
KVRist
 
80 posts since 29 Apr, 2008

Postby hellishvictor; Thu Aug 10, 2017 5:49 am Re: Long script on K4

Awesome! thanks to all of you for the quick response :tu:
hellishvictor
KVRist
 
80 posts since 29 Apr, 2008

Postby hellishvictor; Fri Aug 11, 2017 2:47 am Re: Long script on K4

How about this one?
Code: Select all
      if ($count >= 20)
         select ($count)
            case 20 to 29
               $count := $count -20
               $something := 0
            case 30 to 39
               $count := $count -30
               $something := 1
            case 40 to 49
               $count := $count -40
               $something := 2
            case 50 to 59
               $count := $count -50
               $something := 3
            case 60 to 69
               $count := $count -60
               $something := 4
            case 70 to 79
               $count := $count -70
               $something := 5
            case 80 to 89
               $count := $count -80
               $something := 6

            {and continues until $something := 127
         end select
User avatar
EvilDragon
KVRAF
 
14546 posts since 6 Jan, 2009, from Croatia

Postby EvilDragon; Fri Aug 11, 2017 6:02 am Re: Long script on K4

This doesn't make sense much. Why would you decrease $count by decades? Why not run $count from 0 to 9 instead (yields the same thing)?

You should probably say what you want to do exactly, then we can suggest the most efficient way to loop it. But really, you should rely more on simple math than select-case!
hellishvictor
KVRist
 
80 posts since 29 Apr, 2008

Postby hellishvictor; Fri Aug 11, 2017 11:24 am Re: Long script on K4

Of course it does have sense; its for a menu, like its done on the dynamitec FXScript. $something is every different item group added with +10 and etc. This is for when its selected.
User avatar
EvilDragon
KVRAF
 
14546 posts since 6 Jan, 2009, from Croatia

Postby EvilDragon; Fri Aug 11, 2017 11:51 am Re: Long script on K4

It's quite hard to deduce what you want to do without larger scope (like, the whole callback).
Armagibbon
KVRist
 
409 posts since 20 Apr, 2017

Postby Armagibbon; Fri Aug 11, 2017 5:56 pm Re: Long script on K4

You know man it's def a good call to follow evil dragon's advice there. If you're gonna jump by numbers bigger than 1, you gotta define that value somewhere else and use math to include it in whatever logical stuff you're trying to do here. Because you WILL want to change that value later and it's best to change it 1 time in 1 place than like 30 times in 2 or 3 places you're def not gonna remember to check...
hellishvictor
KVRist
 
80 posts since 29 Apr, 2008

Postby hellishvictor; Sat Aug 12, 2017 12:45 am Re: Long script on K4

ok guys, i'll see if I can to solve it, and if not, I'll leave the select-case system... however, the script is no so long now; it has turn to 400kb from 1700kb it has when I start this topic. Thanks!

Moderator: Moderators (Main)

Return to Instruments