# Update to script compiler



## kotori (Sep 19, 2006)

Hi everyone,
There's now a V1.11 of the script editor/compiler available for download

_Changes_:
constant declarations are automatically moved to the top of "on init" to make it possible to use constants when declaring variables inside functions. Eg. it's now possible to write inside a function: "declare %list[$N]" where $N is a constant without getting the declarations of %list and $N in the wrong order.
 minor fix: it's possible to write comments on the same line as a family declaration
 minor fix: variable names starting with 'select' caused problems with the automatic block ending feature
Cheers,
Nils


----------



## Thonex (Sep 19, 2006)

Native Instruments and all KSP programmers owe you a debt of gratitude. THanks Nils for all your hard work.

Cheers,

T


----------



## Dynamitec (Sep 19, 2006)

Hi Nils!

Again i can just say: Thank you very much! I'm glad you give so much to this community!

:!:


----------



## Nickie Fønshauge (Sep 19, 2006)

Thank you, Nils (as usual - you don't leave me much room for variation :razz: ). Much appreciated


----------



## Big Bob (Sep 19, 2006)

Fantastic Nils!

I've been hoping for this one, ever since you added 'local' vars :mrgreen: . With the addition of 'family' and 'import' the number of situations that got into trouble because of 'constant' forward references (which of course the KSP can't handle), has grown exponentially. So, this fix is a real blessing. Again, thanks a million my friend  .

God Bless,

Bob


----------



## Big Bob (Sep 19, 2006)

Whoops!

Forget the Whoops! I see that Nils already picked it up. This guy is faster than a speeding bullet :wink: .

Bob


----------



## kotori (Sep 19, 2006)

Silly mistake :oops:. Compound statements in the init callback got removed. This is fixed now. Please redownload the V1.11 installation.

Cheers,
Nils


----------



## Thonex (Sep 19, 2006)

kotori @ Tue Sep 19 said:


> Compound statements in the init callback got removed. This is fixed now.



That would have been my first guess too :lol: :lol: :lol: :lol: :lol: :lol:


----------



## kotori (Sep 20, 2006)

There's now a 1.12 version of the editor. Download it here.

The compiler now tries to figure out which functions are only invoked once and invoked directly or indirectly from within 'on init'. These functions are then treated a bit special:
 it's possible to pass arbitrary literals (names) as parameters to them even though these have not been declared.
 it's possible to pass parameters which can be used in declarations, eg. the size of an array.
The good thing about this is that one can pass parameters to the on_init which control the value of constants, size of arrays, names of families and so on, so it's now possible to parameterize the behaviour of modules from the main script. Please try it out and let me know if you find any problems.

Cheers,
Nils


----------



## Big Bob (Sep 20, 2006)

Wow Nils!

I knew this one was in the works but I didn't expect it so soon  . This new feature is a real honey, and I can't wait to try it out. Between this and the prior update to solve the forward-reference problem with constants, I'm going to feel like a kid in a candy store. I'm going to download it and start using it as soon as I finish this post.

Thanks a million Nils for a wonderful tool that just keeps getting better :mrgreen: 

God Bless,

Bob


----------



## Nickie Fønshauge (Sep 20, 2006)

Nils, are there any news on the little problem, where subfamilies (of different families) cannot have the same name?


----------



## kotori (Sep 20, 2006)

Nickie Fønshauge @ Wed Sep 20 said:


> Nils, are there any news on the little problem, where subfamilies (of different families) cannot have the same name?


Yes, please download the 1.13 version. :wink: 

Cheers,
Nils


----------



## kotori (Sep 20, 2006)

Sorry about the frequent updates, but Bob found a bug which has been fixed in version 1.14 which is now available.

Cheers,
Nils


----------



## Nickie Fønshauge (Sep 21, 2006)

kotori @ 20th September 2006 said:


> Yes, please download the 1.13 version. :wink:


Thank you, Nils!!! That is going to save me quite a few keypunches.  [schild=4 fontcolor=C0C0C0 shadowcolor=C0C0C0 shieldshadow=1]Hip, hip hurra![/schild]


----------



## Nickie Fønshauge (Sep 24, 2006)

Hi Nils,

sorry to bother you, but I get a 


> Compilation error
> 'KS0'



I have a file "Instrument data.txt", that contains


````*function* on_init (KS_base,KS0,KS1,KS2,KS3,KS4,KS5,KS6,KS7,KS8,KS9,KS10,KS11,LowNote,HighNote)
````````*family* KeySwitches
``````````*declare* *const* First := KS_base
``````````*declare* *const* Last := KS_base + 11
``````````*declare* *const* KS0 := KS_base
``````````*declare* *const* KS1 := KS_base + 1
``````````*declare* *const* KS2 := KS_base + 2
``````````*declare* *const* KS3 := KS_base + 3
``````````*declare* *const* KS4 := KS_base + 4
``````````*declare* *const* KS5 := KS_base + 5
``````````*declare* *const* KS6 := KS_base + 6
``````````*declare* *const* KS7 := KS_base + 7
``````````*declare* *const* KS8 := KS_base + 8
``````````*declare* *const* KS9 := KS_base + 9
``````````*declare* *const* KS10 := KS_base + 10
``````````*declare* *const* KS11 := KS_base + 11
````````*end* *family*
````````*family* PlayableNotes
``````````*declare* *const* Low := LowNote
``````````*declare* *const* High := HighNote
````````*end* *family*
````*end function*

and another containing
``
``*import* "../../Instrument data.txt" *as* Instrument
``
``*on init*
````Instrument.on_init (36,NoMute,Mute,vacant1,vacant2,Staccato,Marcato,vacant3,vacant4,Trill,Fluttertongue,vacant5,Multiphonics,58,91)
``*end on*

I thought 'NoMute' would replace 'KS0'. Am I doing something wrong? I am using version 1.14.

Cheers

Nickie


----------



## kotori (Sep 24, 2006)

Hi Nickie,
It's pretty late here so I'm just going to bed. Anyway, I looked quickly at this and think I fixed one bug. I reuploaded this slightly updated 1.14 version (yeah I know - I should be more careful with version numbering :wink. Please let me know if it fixes the problem.

Cheers,
Nils


----------



## Nickie Fønshauge (Sep 24, 2006)

kotori @ 24th September 2006 said:


> Hi Nickie,
> It's pretty late here so I'm just going to bed. Anyway, I looked quickly at this and think I fixed one bug. [.....] Please let me know if it fixes the problem.


Hi Nils,

Thanks for responding so quickly. And yes, it did fix it.



kotori @ 24th September 2006 said:


> I reuploaded this slightly updated 1.14 version (yeah I know - I should be more careful with version numbering :wink.


You just need more digits :mrgreen:


----------



## Nickie Fønshauge (Sep 25, 2006)

Hi Nils,

I am afraid I found another bug.

The file "Instrument data.txt" containing


````*function* on_init (KS_base,LowNote,HighNote)
````````*family* KeySwitches
``````````*declare* *const* First := KS_base
``````````*declare* *const* Last := KS_base + 11
``````````*declare* *const* KS11 := KS_base + 11
````````*end* *family*
````*end function*
````
````*function* new_KeySwitch (current_KeySwitch,Multiphonics_KS,Key)
``````*select* Key
````````*case* KeySwitches.KS0 _{No Mute}_
``````````*if* %KEY_DOWN[KS11] = 1
````````````Multiphonics_KS := 0
````````````current_KeySwitch := 11 + Multiphonics_KS
``````````*else*
````````````current_KeySwitch := 0
``````````*end if*

and another file containing

 
``*import* "../../Instrument data.txt" *as* Instrument
``
``*on init*
````
````Instrument.on_init (36,58,91)
````
``*end on*


``*on note*
````*select* EVENT_NOTE
``````*case* Instrument.KeySwitches.First *to* Instrument.KeySwitches.Last _{Keyswitches}_
````````Instrument.new_KeySwitch (current_KeySwitch,Multiphonics_KS,EVENT_NOTE)
````*end select*
``*end on*

give me an error message "Instrument.KS11 not declared".


----------



## kotori (Sep 25, 2006)

Hi Nickie,
Thanks for the error report. Bob notified of this problem as well. I'm trying to fix it. As a temporary workaround you can try to declare the variable as global:
"declare _global_ const KS11 := KS_base + 11"

Cheers,
Nils


----------



## Nickie Fønshauge (Sep 25, 2006)

Hi Nils,

Thank you for the feedback. I'll try your workaround.

Cheers

Nickie


----------



## Big Bob (Sep 25, 2006)

This is probably a very dumb question Nickie but shouldn't the 'red' KS11 subscript be coded as: KeySwitches.KS11 ? Besides, aren't all the constants declared inside of the on_init function implicitlly global? Maybe I haven't totally caught on to this 'family' stuff yet?

Bob


----------



## kotori (Sep 25, 2006)

Big Bob @ Mon Sep 25 said:


> This is probably a very dumb question Nickie but shouldn't the 'red' KS11 subscript be coded as: KeySwitches.KS11 ? Maybe I haven't totally caught on to this 'family' stuff yet?
> 
> Bob


That is a very good point! :smile:


----------



## Big Bob (Sep 25, 2006)

Hi Nils,

Wow, you're fast, you quoted my post before I completed my edit to it! I tried to add the part about KS11 is already declared implicitly as 'global' anyway. But, you lifted my post before I could slip it in. :oops: 

Bob


----------



## Nickie Fønshauge (Sep 25, 2006)

Big Bob @ 25th September 2006 said:


> This is probably a very dumb question Nickie but shouldn't the 'red' KS11 subscript be coded as: KeySwitches.KS11 ?


No, Bob, it is certainly not a dumb question and you are absolutely right :oops: I sometimes forget this little detail :lol: I am trying to learn the new family & import features; it's very cool  but a little confusing until you get the hang of it.


----------



## Big Bob (Sep 25, 2006)

Nickie Fønshauge @ Mon Sep 25 said:


> Big Bob @ 25th September 2006 said:
> 
> 
> > This is probably a very dumb question Nickie but shouldn't the 'red' KS11 subscript be coded as: KeySwitches.KS11 ?
> ...



Don't feel bad Nickie, it happens to all of us :???: .


----------



## Nickie Fønshauge (Sep 26, 2006)

Nils, when I have a file with

````*function* on_init (name6,first6,total6)
``````*family* name6
````````*declare* first_group := first6
````````*declare* total_groups := total6
``````*end* *family*
````*end function*

which is being imported into another file containing


``
``*import* "../Pro Musica Solo Westgate.txt" *as* Westgate
``
``*on init*
````
````Westgate.on_init (release,35,1)
``````
``*end on*

shouldn't I then be able to reference variables _Westgate.release.first_group_ and _Westgate.release.total_groups_? These two variables are reported "not declared"; instead variables _release__first_group_ and _release__total_groups_ are being declared. Or did I just miss something again? :wink:

EDIT: definitely something wrong, Nils.

As soon as I embed "family name6" in another (dummy) family, all variables get the correct "Westgate" prefix; without the dummy family, they don't get the "Westgate" prefix.


----------



## kotori (Sep 26, 2006)

Hi Nickie

That's odd - my editor seems to hang when given this script. :???: 
I'll look into it. You might want to be a bit careful using this new possibility of passing names as parameters. It seems it's not completely stable yet. I'll try my best to fix it.


----------



## Nickie Fønshauge (Sep 26, 2006)

kotori @ 26th September 2006 said:


> Hi Nickie
> 
> That's odd - my editor seems to hang when given this script. :???:
> I'll look into it. You might want to be a bit careful using this new possibility of passing names as parameters. It seems it's not completely stable yet. I'll try my best to fix it.



Oh, I am careful. I test compile quite often to see, if I have gotten it right - I don't always, you know :wink: But, I do like these new features and I try to use them as much as possible.

The script I posted is edited down for simplicity, but I just tried it in the editor and it does compile (when both script parts have been saved) - no hanging, so I don't know what was wrong when you tried it.

This is the compiled code:

```
on init 
        declare $release__first_group := 35 
        declare $release__total_groups := 1 
     
    {begin Westgate__on_init(release,35,1)}
        {family release}
    {end Westgate__on_init(release,35,1)}
       
  end on
```

Watch the difference, when I change the imported file to

*function* on_init (name6,first6,total6) 
``*family* dummy
````*family* name6 
``````*declare* first_group := first6 
``````*declare* total_groups := total6 
````*end* *family* 
``*end* *family*
*end function*

Then I get:


```
on init 
      declare $Westgate__dummy__release__first_group := 35 
      declare $Westgate__dummy__release__total_groups := 1 
     
    {begin Westgate__on_init(release,35,1)}
    {family Westgate__dummy}
      {family release}
    {end Westgate__on_init(release,35,1)}
       
  end on
```


----------

