BBC BASIC for Windows
« Obvious bug or I'm idiot »
Welcome Guest. Please Login or Register. Apr 5th, 2018, 11:51pm
ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018. Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.
If you require a dump of the post on your message board, please come to the support board and request it.
Obvious bug or I'm idiot
« Thread started on: May 23rd, 2012, 05:56am »
Code:
print fn_Func1(0)
end
def fn_Func1(Number%)
print "Init"
local Answer% = Number%
print "Calc"
= Answer%
Why I don't see "Calc"?
Logged
I wanted to do something. I wanted to do something as badly as a genie who's been let out of his bottle for the first time in a thousand years. Anything at all: Raise up castles, lay waste cities, program in Basic, or embroider in cross-stitch. -- Nochnoy Dozor (The Night Watch) By Sergei Lukyanenko
print fn_Func1(0)
end
def fn_Func1(Number%)
print "Init"
local Answer% = Number%
print "Calc"
= Answer%
Why I don't see "Calc"?
Because you're trying to initialise a variable in the LOCAL statement. I agree that it would be nice if you could, but BBC BASIC has never had that facility: you have to separate it into two statements as follows:
Code:
PRINT FN_Func1(0)
END
DEF FN_Func1(Number%)
PRINT "Init"
LOCAL Answer%
Answer% = Number%
PRINT "Calc"
= Answer%
Now you know why it didn't work, it would be a useful exercise for you to work out why it didn't produce an error message (hint: a statement starting with an equals sign = is valid, and BBC BASIC doesn't always need a colon separating statements)!
Re: Obvious bug or I'm idiot
« Reply #2 on: May 23rd, 2012, 10:43am »
In other words, BBC BASIC understand my code like this:
Code:
print fn_Func1(0)
end
def fn_Func1(Number%)
print "Init"
local Answer%
= Number%
Very funny. There is even a peculiar charm in such unexpected unobviousnesses, which has an own logic.
Logged
I wanted to do something. I wanted to do something as badly as a genie who's been let out of his bottle for the first time in a thousand years. Anything at all: Raise up castles, lay waste cities, program in Basic, or embroider in cross-stitch. -- Nochnoy Dozor (The Night Watch) By Sergei Lukyanenko