# Variable not declared error message



## daringone (Jun 4, 2012)

Hello,

Working on a little script and have written a function which is giving me trouble, wondered if one of you may be able to assist 

Heres the function. The array that I pass is psuedo 2 dimensional using the KSE properties feature.


```
function ResetRow(Array, Row)
{This function takes the Row number and a multidimensional array and fills it with BLANK data}
    
    declare i {counter}

    for i := 0 to 127 {Array is 128*128}
        Array[i,Row] := BLANK {Reset each index of the row}
    end for
    
end function
```

When I hit compile in KSE it I get the following error message

Row has not been declared!
Array[i,Row] := BLANK

Any ideas? I think it is something to do with passing the Array to the function but not 100% sure.


----------



## Big Bob (Jun 4, 2012)

I'd really like to see your property definition (or defining macro) before I comment on this. :roll:

Upon further reflection, I think you are right in that I don't think you can pass a property name as a KS function parameter. You should be able to do this with a macro though.

Rejoice,

Bob


----------



## daringone (Jun 4, 2012)

Thanks for the reply Bob, here is the property, I haven't used a macro.


```
declare RRArrayData[127*127] := (BLANK){This array is 127*127} {Fill the array with BLANK's because this number wont come up}
    property RRArray
        function get(x,y) -> result
            result := RRArrayData[x*127+y]
        end function
        function set(x,y,value)
            RRArrayData[x*127+y] := value
        end function
    end property
```

The function works fine if I just use the RRArray directly but I get that error when I try to pass it in as a parameter


----------



## Big Bob (Jun 4, 2012)

Yes, functions are more limited than macros when it comes to the kind of names you can pass. With KS functions, I know you can pass family names and oridinary array names. You can also (once again) pass the names of executable KS functions. But, appranently not property names. If Nils ever comes up for air again, maybe he can comment on this.

However, as I already indicated you *can* pass a property name with a macro so I think generally, you should be able to accomplish what you are trying to do. Since you intended *ResetRow* to be a KS function anyway, every reference will be expanded inline so I don't see much penalty for just coding it as a macro instead. Of course you will have to do an 'end run' around the local var i. The easiest way to handle that might be to declare it globally with a prefix to keep from conflicts (but that's all the KSE does with local variables anyway. (ie apart from task functions which now have true local vars).

Rejoice,

Bob


----------



## daringone (Jun 5, 2012)

Thanks Bob, i'll see what I can do with it


----------



## kotori (Jun 6, 2012)

This was a bug in KScript Editor. When, as part of the function inlining (which btw is different than macro inlining), an array name and its subscript are both to be substituted I failed to invoke a recursive substitution on the latter. This caused the subscript to be left untouched. I have now fixed it in the source code so it should work in the next release of KScript Editor. The mistake was introduced when I added support for (pseudo-)arrays with multiple subscripts. I have now added this to the test cases (currently 91 of them) to avoid future regressions. Here's the code that doesn't work in the current release but will work in the next:

*function* set_value_at(array, index, value) 
``array[index] := value
*end function*

*on init*
``*declare* my_array[100]
``set_value_at(my_array, 0, 10)``
*end on*

Thanks for bringing it to my attention.

-- Nils


----------



## Big Bob (Jun 6, 2012)

Hi NIls, welcome back (even if it will only be briefly) o-[][]-o 

Glad you were able to fix this one also.

And, while you're here, maybe you can clarify something for me? I happened to notice that one can add a new keyword, such as *otherwise*, to the *builtins.txt *file and it will then be syntax highlighted but, if one uses the 'Copy as BB code' feature and then pastes that in a forum post, the syntax highlighting doesn't seem to show.

Is there some other action that one needs to take to make that happen? Or, shouldn't I be fiddling with these files at all? :lol: 

Rejoice,

Bob


----------



## daringone (Jun 6, 2012)

Fantastic! I look forward to the next release!


----------



## kotori (Jun 6, 2012)

Hi Bob,

I have uploaded a new version of KScript Editor (only for Windows so far). I think customizations of builtins.txt should affect html output with this version.

Cheers,
Nils


----------



## mk282 (Jun 6, 2012)

Thanks for the update, Nils!


Quick question - does this version include inlining macros within macros? (You supplied me with ksp_compiler.py file that had it enabled, so basically what I'm asking is do I still need to include it in library.zip, or is the .pyo inside up to date)?


BTW - seems like importing "Parameters.ksp" include does not work anymore. Error:

"Syntax error (line 4)
property insert.volume

Imports/Parameters.ksp:103

Imports/Parameters.ksp:36"


Also - wouldn't it make more sense for the horizontal scrollbar only to show up when there's actually some text needed to scroll? Otherwise gray it out.


Thanks!


----------



## Big Bob (Jun 6, 2012)

Hi Nils,

Thanks for the new update but unfortunately some problems have apparently crept in.

Most of the new things I tried (such as the new else clause in select constructs) seem to be working as far as I got, however, *I haven't been able to compile anything of significance without getting errors*. I haven't tracked them all down yet but here are two that popped up right away (plus a third I just ran into).

1. Functions with return values ( such as the following) no longer compile:

*on init*
``*declare* x
``message(test(x))
*end* *on*

*function* test(n) -> result
``result := n*n
*end function*


2. Constants can no longer be specified in hex. For example:

*on init*
``*declare* *const* abc := 0x7F
``message(abc)
*end* *on*


3. Apparently there is also some kind of error affecting property declarations. For example, this code which compiles OK with the interim V1.5.2 but not with the latest V1.5.2.

*on init* 
``*declare* i
``new_2d(MyArray,10,10) 
``new_2d(YourArray,5,8 ) 
``MyArray[4,5] := YourArray[3,7]
*end on* 

*macro* new_2d(#name#,rows,cols) 
``*declare* _#name#[rows*cols] 
``*property* #name# 
````*function* get(x, y) -> result 
``````result := _#name#[x * cols + y] 
````*end function* 
````*function* set(x, y, value) 
``````_#name#[x * cols + y] := value 
````*end function* 
``*end property*````
*end macro*

It's going to be difficult for me to find other specific errors because almost all of my non-trivial source code uses RV functions and I use a lot of hex data specifiers. So those two error mechanisms alone make it tough to get any farther through the compilation process.

Sorry to be bearer of bad news.

Bob

But: *Hey Nils, this is getting exciting again*, apparently there is at least some kind of nested macro capability in the latest version. Hopefully I can explore this a little more but right now the above problems keep getting in the way.


----------



## kotori (Jun 7, 2012)

Hi Bob,

oops - apparently a modification that I made in order to let you customize the keywords for HTML export changed the working directory somehow, which created problems. I have reverted that last change for now. Pleae download again.

You are correct regarding macros. Calling macros from macros is now allowed, but it hasn't been subject to much testing yet so please use this particular feature with some care.

Cheers,
Nils


----------



## Big Bob (Jun 7, 2012)

HI Nils,

Good News/Bad News

All the stuff that wasn't working yesterday is now working OK. Sorry if I was the cause of all that trouble with my HTML query :lol: 

There is however, another problem with the new V1.5.2. Apparently, the set_event_par_arr stuff must have dropped out. I haven't checked the builtins to see if it's missing yet but I thought I had better report the problem first. The following routines are no longer accepted by the new version.

*function* off_groups(id)
``set_event_par_arr(id,EVENT_PAR_ALLOW_GROUP,0,ALL_GROUPS)
*end function* _{ off_groups }_

*function* off_group(id,n)
``set_event_par_arr(id,EVENT_PAR_ALLOW_GROUP,0,n)
*end function* _{ off_group }_

*function* on_group(id,n)
``set_event_par_arr(id,EVENT_PAR_ALLOW_GROUP,1,n)``
*end function* _{ on_group }_

As soon as I finish posting this I'll check the bulitins.txt file to see if I can spot anything amiss.

BTW That's wonderful news about the nested macro thing, (not to mention the horizontal scrolling). I'll try to do some thorough testing of nested macros ASAP to see if I can find anything amiss. Looks like its going to be another super update o-[][]-o 

God Bless,

Bob

EDIT: The set_event_par_arr function *does* seem to be missing from the builtins.txt file. I copied it from the interim V1.5.2 and now the new V1.5.2 seems to be working OK in this area. I am now able to compile all the WIPS scripts without error. I haven't had time to check things functionally so I'll get to that as soon as I can but, so far so good. 8)


----------



## andreasOL (Jun 7, 2012)

Hi,

nested macros is reeeaaally good news for me. This will help me a lot in modularizing my code.

Will start testing it today or tomorrow.

Thanks, Nils, and thanks, Bob, for all your work!!!

best,
Andreas


----------



## kotori (Jun 7, 2012)

Oh, that was a misunderstanding. Evil Dragon asked me to remove two _arr functions from builtins.txt and I must have removed the wrong ones - I was in a bit of a hurry. I put them back now and also added a link to the latest compiler source code.


----------



## Big Bob (Jun 7, 2012)

Whoops, I just noticed that Find no longer works :( 

Could this be related to this item in the Change Log?



> Find: selection doesn't change when no further matches can be found.



BTW So far so good with nested macros but I'll keep using it.

God Bless,

Bob


----------



## kotori (Jun 7, 2012)

Hi Bob, if you download the latest installer I hope it should work. I also activated up/down options for the search function.


----------



## andreasOL (Jun 8, 2012)

huh...

regarding "Find..."

It works one time, then it finds no further occurrence. But if I click somewhere behind the position of the current find (i.e. the caret is visible again) it finds the next one.

"Replace..." is also broken. It has no replace field, only the search field.

- Andreas

PS: Used the latest installer.


----------



## mk282 (Jun 8, 2012)

Nils, you've some bad karma there... :/


----------



## Big Bob (Jun 8, 2012)

> PS: Used the latest installer.



Andreas, I presume you mean the one Nils just posted? I guess I had better skip this update and wait for the next fix then :lol: 

OK Nils, time to 'serious up' here >8o


----------



## andreasOL (Jun 8, 2012)

Big Bob @ Fri 08 Jun said:


> > PS: Used the latest installer.
> 
> 
> 
> ...



Yes, I downloaded and installed again right before I posted this.

These look like easy to fix errors. Last minute or even last second mishaps I know too well, too


----------



## kotori (Jun 8, 2012)

It works now.


----------



## Big Bob (Jun 8, 2012)

Hi Nils,

Yes, indeed. :D Everything now seems to be working well with V1.5.2.

I've also been testing the nested macro feature pretty thoroughly and so far no glitches. This is a great new addition that has been on my wishlist for a long time and I'm so glad to see it.

I love having the horizontal scroll and having the up/down find/replace options working is also quite useful. All in all another wonderful update Nils.

Many, many thanks o-[][]-o 

(and time to visit Pay Pal again me thinks)

Rejoice,

Bob


----------



## mk282 (Jun 9, 2012)

"Match Case" doesn't seem to work with both Find and Replace dialogs. It disregards case completely.

Same thing for "Match Whole Word Only".

I don't see "Up/Down" radio-buttons in Replace dialog.


----------



## Big Bob (Jun 9, 2012)

mk282 @ Sat Jun 09 said:


> "Match Case" doesn't seem to work with both Find and Replace dialogs. It disregards case completely.
> 
> Same thing for "Match Whole Word Only".
> 
> I don't see "Up/Down" radio-buttons in Replace dialog.



Whoops! I didn't actually check the 'matching' conditions (which of course all used to work properly before). Good catch MK, I hope Nils can find the time to fix this.

I did notice the lack of Up/Down options in the Replace dialog but thought that was probably intentional or necessary (since they've never been there, even grayed out).


----------

