Questions from the B3D communtiy

BlitzMax Forums/BlitzMax Programming/Questions from the B3D communtiy

Paul "Taiphoz"(Posted 2005) [#1]
Hi all. Please take a second to read this when you see new posts to it.

I will be passing on question from the blitz 3D community, some of the guys over there want to know more before they spend money on max and you guys are the best to ask about it.

I will just drop their Q's in the form of quotes like the first one here bellow.


JoJo (Posted 2005-01-01 03:13:22)
Thanks for that.
1:) My question is; When a function is declared inside types, is that function Global? It looks some people use a function to instantiate more types.

2:) And by using functions this way, is it similar to constructors?


JoJo (Posted 2005-01-01 03:19:20)
1:) When do variables loose their scope?
If I declare a variable inside an if...endif block, is scope lost when it exits?

2:) What about in methods and functions declared inside types?
As I look over some examples, I assume when you delcare a variable using the Local keyword then it should be local to that block of code.


3:) And also when you're accessing members, member functions and etc; is there some type of intellisense that comes up?




Perturbatio(Posted 2005) [#2]
1:) My question is; When a function is declared inside types, is that function Global? It looks some people use a function to instantiate more types.


Yes, it is global.

2:) And by using functions this way, is it similar to constructors?


yes

If I declare a variable inside an if...endif block, is scope lost when it exits?

in this code:

a = Rand(5)

If a > 0 Then
	b = 5
	Print b
EndIf

Print b


b=5 inside and outside the if statement

however, there is currently an issue with the Win32 Beta where if you declare a global inside an if statement, it becomes local to that block. If you declare it as global outside the if statement and use it inside, it works fine.
(I hope Mark will fix this sometime soon (unless it is intended functionality)).

a = Rand(5)

If a > 0 Then
	Global b = 5
	Print b
EndIf

Print b

b=5 inside the block, b=0 outside.


2:) What about in methods and functions declared inside types?
As I look over some examples, I assume when you delcare a variable using the Local keyword then it should be local to that block of code.



Local makes variables local to the function or method.
You do not appear to be able to currently declare globals inside functions or methods. (presumably for the same reasons as inside an if block).


Phish(Posted 2005) [#3]
Talking of which, wouldn't it be a better idea if once you had bought any Blitz product, you had access to any of the communities? Only I remember being very frustrated before I bought BlitzMax that I couldn't ask people about BlitzMax on the forums.

Administrators still have power over them if they abuse the forums, so why not?


Mark Tiffany(Posted 2005) [#4]
however, there is currently an issue with the Win32 Beta where if you declare a global inside an if statement, it becomes local to that block. If you declare it as global outside the if statement and use it inside, it works fine.
(I hope Mark will fix this sometime soon (unless it is intended functionality)).

I *think* that's intended behaviour. If you declare local a variable (either explicitly with local, or implicitly in non-strict mode), then it is only in scope within that block of code (if, loop, whatever).

Lesson 1: Use Strict, and declare all variables at the top of a function.


Dreamora(Posted 2005) [#5]
global declaration within anything outside the mainscope shouldn't be possible at all.

Local just local to their scope ( function / method / "rest" )

every behavior outside of this isn't very wishable or "right" out of the general use of this quite important keywords.

If is no scope, it has no own stack so no own variable space as well.


RexRhino(Posted 2005) [#6]
global declaration within anything outside the mainscope shouldn't be possible at all.

What do you mean by mainscope? Globals inside types are very useful, if you want all types to share certain information (for example, if you have a button class, and you want a function that returns the last button clicked regardless of what button you query).


FlameDuck(Posted 2005) [#7]
global declaration within anything outside the mainscope shouldn't be possible at all.
Sure they are. Fields that are global to the type scope, aka. Class/Static variables, most languages have them.

If is no scope, it has no own stack so no own variable space as well.
It does actually.