2014-08-17 21:11:41

Well, since the Dragonflame engine doesn't have any game-related features and I think is rather limited at the moment, despite about one person attempting to create a game with it, I've decided to attempt to learn BGT again as, while PureBasic seems like a good option as well, BGT is designed with the mindset of "I want to create a game as quickly as possible" after I get a few concepts down. IDK, what are all of your thoughts on this issue? Warning: The topic could be spread over multiple pages if this discussion gets intense.
So, I was trying to use the John Doe example in the language tutorial. I didn't do exactly as the example said because it didn't have things like void main for actually creating a script. Here's my code, and I don't get the compilation error.
// This creates the string variable with the value Josh, to be displayed when "alert" is called.
string My_Name="Josh";
// This turns the script into reality when compiled.
void main()
{
// This calls the alert function to display a dialogue with the assigned value to My_Name.
alert (My Name", "My name is My_Name);
}

2014-08-17 22:00:17

Hello there Orin. Firstly, I'd like to say that I didn't actually run my solution through the compiler, but I'm quite sure that I have found the issue.
Basicly, in BGT, whenever you are using strings when dealing with parameters of functions, they must be surrounded by quotation marks, unless you are using a variable. For example:
string day="monday";
void main() {
alert("info", "Hello, today is "+day);
}


So, the only line in your example that is slightly incorrect is:
alert (My Name", "My name is My_Name);

But all one needs to do to fix it is add a quotation mark after the opening parenthesis, and add a quotation mark followed by a plus sign after "my name is". The correct line should say:
alert("My Name", "My name is"+My_Name);

P.S. I think the space between Alert, and the opening parenthesis might cause a problem as well. But the plus sign just links the variable to the "My name is" text. smile

Go to Heaven for the climate, Hell for the company. - Mark Twain

2014-08-17 23:46:49

Oops, I forgot the first quote. Ah well, thanks for the help though. Got it now.

2014-08-18 01:18:29

Okay, now this is downright weird. I do everything the documentation says, but the compiler is bugging me about the return value of result and the right brace to end the function. The code is below. The return result; and it's associating right brace to end that function and the script is right, so WTF?

//This starts the script, as usual.
void main()

{
//This creates an intigral variable called X, with a function inside it called ANumbers which stores two numbers.
int x=anumbers(3, 5)
//Displays a message box with the "result" value of the intigral variable created above.
alert(Nice!", "3 + 5 is " + x + ".);
}
//This adds two intigral variables to ANumbers, which tells the compiler to put each number in it's own variable to be refered to later.
int x=anumbers(int first, int second)

{
//This is the actual "result" variable, which tells the compiler we want to add the numbers. If I were to put a * here, the message box would say that 3+5 equals 15 because the compiler will multiply.
int result=first+second;

//This functions return value is the result, 8.

return result;

}


Not sure why it's not compiling right though.

2014-08-18 05:31:17

There are three (well, technically 4) errors:
1. You're missing a semicolon when you first define x.
2. The first and last quotes in the alert are missing again.
3. When you define the function, you don't need the x=.

HTH

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2014-08-18 19:48:14

Thanks for the help, again. Ugg I guess I'll write the dang two quotes and parens first so that I won't forget them, then just put whatever goes between. I'll remember eventually. This is why I'd love an IDE because this is what autocomplete is for.

2014-08-18 22:10:53

An ide won't actually autocomplete semicolons or brackets. the only real autocomplete I've seen is for function and variable name completion.

Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.

2014-08-19 00:01:33

Not true.  You can get bracket completion.  Not ; though. XCode does, Eclipse does with the right Plugins, and I think VS does but am not sure.
And, as usual with IDEs, it ends up not being as worth it as you might imagine.  It's only reall a problem when you nest 5 or more levels deep.  And, while not good practice, you will at some point.

My Blog
Twitter: @ajhicks1992

2014-08-19 20:41:19 (edited by Orin 2014-08-19 20:46:24)

Okay, so mine still won't compile. What I've decided to do was create two files. One with the document I'm trying in, the other is a pasted document from the documentation example, except I changed the names of the variables and functions to correspond with what I personally changed them to because I don't like typing "add_numbers" every time, would rather just do anumbers. First, I'll give the pasted document, which actually works and I have yet to figure out why, and then I'll give the one I'm typing in, which from looking at the pasted docs is the *exact* same thing. Then I'll give the compilation error that the compiler is throwing at me. I believe I fixed the semicolon quotes error that someone pointed out earlier.
Motified from doc:
void main()
{
int x=anumbers(3, 5);
alert("Wow", "3 + 5 is " + x + ".");
}
int anumbers(int first, int second)
{
int result=first+second;
return result;
}

The one I'm typing in and testing:
//This starts the script, as usual.
void main()

{
//This creates an intigral variable called X, with a function inside it called ANumbers which adds two numbers.
int x=anumbers(3, 5);
//Displays a message box with the "result" value of the intigral variable created above.
alert("Nice", "3 + 5 is " + x + ".");
}
//This adds two intigral variables to ANumbers, which tells the compiler to add the first, followed by the second. 3, 5.
int x=anumbers(int first, int second)
{
int result=first+second;
return result;
}

//End Script.

Compilation error:
File: C:\BGTStuff\Learning Files\functions.bgt
On line: 14 (1)
Line: return result;
Error: Unexpected token 'return'

File: C:\BGTStuff\Learning Files\functions.bgt
On line: 15 (1)
Line: }
Error: Unexpected token '}'

WTF? The forum put brackets in the alert function for the pasted doc. Those aren't there in the actual document. Is that what it does for quotation marks?

2014-08-19 20:51:18 (edited by stewie 2014-08-19 20:52:26)

You can not declare functions that are equal to an integer variable that way.

The problematic code:
int x=anumbers(int first, int second)

A function call works like this.
The function is called. You pass parameters to it, like your first and second example above. The function evaluates whatever, then, unless it's a void, returns anything you want.

int x=anumbers(int first, int second)
The problem with this code is that int x will declare a variable to the left of the equals sign. So what that line signifies is that your declaring a variable which will be equalled to the output of a function that doesn't exist yet.

The correct code:
int anumbers(int first, int second)

This just declares a function with the return type being integer.

Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.

2014-08-19 22:59:07

(The wow brackets are just the spam filter. I don't know if they're still around, but bots peddling World of Warcraft Gold with lots of links were extremely common a few years ago, so the brackets get added to break their posts without removing anything from legitimate posts.)


This is one advantage that scripting languages like Javascript and Python and I believe VBScript have for newbies: the syntax of functions is not easy to confuse with variables. The downside is that the first two don't specify a return type, which can have drawbacks if you aren't careful (and makes for more confusion if you want to learn a lower level language later).

Compare:

// Javascript:
function anumber(x, y)
{
return x+y;
}

# python
def anumber(x, y) :
    return x+y

// BGT/C/etc:
int anumber(x, y)
{
return x+y;
}


You don't specify an output variable in any case, but in the last, you do specify the type of variable to return. (There is a reason, but I get how it can be confusing.)

Calling the function still works like

int x=anumber(5, 3);

I have no idea if this post is helpful. sad

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2014-08-20 05:05:08

Thanks, Stewie. I saw your post the other day about how I didn't need an equals sign, but I wonder why the documentation has it in it's example. I guess it works in some form, but I'll take it out if I don't even need it.

2014-08-20 05:21:07

From what I see in the tutorials, their implementation of add_numbers is correct.

Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.