Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NaaLaa Object Names bug ???
#1
Bug 
Hi everyone

I started to consult NaaLaa help and then i saw "objects". Yes i want OOP.
But then i saw "Objects are variables that can contain other variables".
I can't add methods ? No ? Ok no problem i am open minded.[Image: smile.png]

Let's try it. Just run this code. No problems in here.

Code:
rem my first object

person?
person.age=11
wln person.age
wln "Press space key to exit ..."
wait keydown

Result:11

Now add a number to object name. Just change it to "person1" and run it. So far so good.


Code:
rem my first object
person1?
person1.age=11
wln person1.age
wln "Press space key to exit ..."
wait keydown
result: 11


Now the bug [Image: bug.png]:

Change the age field to 22 and run it ... and you will get 11. Weird. Bug alert [Image: bug.png] or you can't put numbers in object names [Image: wink.png]


Code:
rem my first object
person1?
person1.age=22
wln person1.age
wln "Press space key to exit ..."
wait keydown

result: 11
Reply
#2
Can you post the full code that you are running? have you done in the same file both person? and person1? objects? if you use both object1? in the same file it will stay with the same values cause it's the same object and it will not be changer, now if you change the var name it will change to 22 the age.

(06-15-2018, 10:13 AM)pedromartins Wrote: Hi everyone

I started to consult NaaLaa help and then i saw "objects". Yes i want OOP.
But then i saw "Objects are variables that can contain other variables".
I can't add methods ? No ? Ok no problem i am open minded.[Image: smile.png]

Let's try it. Just run this code. No problems in here.

Code:
rem my first object

person?
person.age=11
wln person.age
wln "Press space key to exit ..."
wait keydown

Result:11

Now add a number to object name. Just change it to "person1" and run it. So far so good.


Code:
rem my first object
person1?
person1.age=11
wln person1.age
wln "Press space key to exit ..."
wait keydown
result: 11


Now the bug [Image: bug.png]:

Change the age field to 22 and run it ... and you will get 11. Weird. Bug alert [Image: bug.png] or you can't put numbers in object names [Image: wink.png]


Code:
rem my first object
person1?
person1.age=22
wln person1.age
wln "Press space key to exit ..."
wait keydown

result: 11


if you do like this it works as supose to, 11 and 22.

Code:
rem my first object
person1?
person1.age=11
wln person1.age

person1.age=22
wln person1.age

wln "Press space key to exit ..."
wait keydown
Reply
#3
(06-15-2018, 01:45 PM)cvirus Wrote: Can you post the full code that you are running? have you done in the same file both person? and person1? objects? if you use both object1? in the same file it will stay with the same values cause it's the same object and it will not be changer, now if you change the var name it will change to 22 the age.

(06-15-2018, 10:13 AM)pedromartins Wrote: Hi everyone

I started to consult NaaLaa help and then i saw "objects". Yes i want OOP.
But then i saw "Objects are variables that can contain other variables".
I can't add methods ? No ? Ok no problem i am open minded.[Image: smile.png]

Let's try it. Just run this code. No problems in here.

Code:
rem my first object

person?
person.age=11
wln person.age
wln "Press space key to exit ..."
wait keydown

Result:11

Now add a number to object name. Just change it to "person1" and run it. So far so good.


Code:
rem my first object
person1?
person1.age=11
wln person1.age
wln "Press space key to exit ..."
wait keydown
result: 11


Now the bug [Image: bug.png]:

Change the age field to 22 and run it ... and you will get 11. Weird. Bug alert [Image: bug.png] or you can't put numbers in object names [Image: wink.png]


Code:
rem my first object
person1?
person1.age=22
wln person1.age
wln "Press space key to exit ..."
wait keydown

result: 11


if you do like this it works as supose to, 11 and 22.

Code:
rem my first object
person1?
person1.age=11
wln person1.age

person1.age=22
wln person1.age

wln "Press space key to exit ..."
wait keydown

I run your program once. Everything was right. Then i changed 22 to 33 and run it again ... and i get 22 ... It's wierd. My full code is the two little programs i post. One with object person? and the other with object person1? [Image: smile.png]
Reply
#4
That is strange, but i'm using the latest linux version do not know if there is any diference between them, i change as you said and worked ok, with the 22 and 33 values.
Reply
#5
(06-15-2018, 03:02 PM)cvirus Wrote: That is strange, but i'm using the latest linux version do not know if there is any diference between them, i change as you said and worked ok, with the 22 and 33 values.


I am using windows version. [Image: sad.png]
Reply
#6
Do you close the running program before running it again? A new executable can't be created if the program's running.
Reply
#7
You're right, there's something really weird happening when you put a number at the end of the name of an "object" variable. It actually causes the compiler NOT to compile the program at all. If you create a new program and paste the code into it, no sbe or executable will be created when you compile it.

You're good at finding bugs, haha Smile I've written several games with thousands of code lines each, and I've never stumbled upon any of the things you've found.

Edit
If you make an assignment to a field during "declaration" it works:

Code:
person1?.age = 2
person1.age = 75
wln person1.age
wln "press space key to exit ..."
wait keydown

I'll fix it as soon as I get the time Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)