Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
array has not been initialized error for no apparent reason [solved]
#1
Bug 
I ran into this problem for a second time, i want to init an object using a function instead of writing alot of attributes.
and I get this error



this  code recreates the problem in a simplified way:

Code:
items?[5]

rem this works fine
items[0] = createItem(1,2)
rem this dosnt work
c = createItems(items)


rem create objects
function createItems(&its?[])

    for i=0  to sizeof(its)-1
        rem this line returns error
        b? = createItem(1,2)
        its[i] = b

    rem
    next

endfunc

rem create object
function createItem?(x,y)

    i?
    i.x=x
    i.y=y
    return i
endfunc


wait keydown

hacked my way out of this one myself (if anyone has a better way ill be glad to see it).

I leave this as a future reference.

the solution:

Code:
items?[5]


rem now it works
items?[] = createItems(5)


rem create objects
function createItems?[](objnum)
    its?[objnum]
    for i=0  to sizeof(its)-1
        b? = createItem(1,2)
        its[i] = b

    rem
    next
    return its
endfunc

rem create object
function createItem?(x,y)

    i?
    i.x=x
    i.y=y
    return i
endfunc


wait keydown
Reply
#2
(01-30-2019, 05:43 PM)rolen Wrote: I ran into this problem for a second time, i want to init an object using a function instead of writing alot of attributes.
and I get this error



this  code recreates the problem in a simplified way:

Code:
items?[5]

rem this works fine
items[0] = createItem(1,2)
rem this dosnt work
c = createItems(items)


rem create objects
function createItems(&its?[])

    for i=0  to sizeof(its)-1
        rem this line returns error
        b? = createItem(1,2)
        its[i] = b

    rem
    next

endfunc

rem create object
function createItem?(x,y)

    i?
    i.x=x
    i.y=y
    return i
endfunc


wait keydown

hacked my way out of this one myself (if anyone has a better way ill be glad to see it).

I leave this as a future reference.

the solution:

Code:
items?[5]


rem now it works
items?[] = createItems(5)


rem create objects
function createItems?[](objnum)
    its?[objnum]
    for i=0  to sizeof(its)-1
        b? = createItem(1,2)
        its[i] = b

    rem
    next
    return its
endfunc

rem create object
function createItem?(x,y)

    i?
    i.x=x
    i.y=y
    return i
endfunc


wait keydown

That appears to be a … bug :Smile I'm terribly sorry and hope to get a chance to fix it soon!
Reply
#3
thanks.

I created a small scripting language once so I understand that things like that happen. not that I'm at your caliber as a programmer.

I found a way around. naalaa is great.

again thanks.
Reply
#4
(01-31-2019, 03:47 PM)rolen Wrote: thanks.

I created a small scripting language once so I understand that things like that happen. not that I'm at your caliber as a programmer.

I found a way around. naalaa is great.

again thanks.

I'm very sorry for not being here for a while Sad

I just fixed this bug, after not having looked at the naalaa sourcecode for a long time. I'll see if I can fix some other things while I'm at it. 

Sorry for keeping you waiting.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)