2014-11-28 17:40:14

hello, I have just gotten into the Business of coding, and have the language tutorial and everything else I Need open as i write this message. Problem is, I have al lready written a bit of code working on a blackjack game. however, the game keeps throwing up a compulation error at line 9 character 6. the line of code there is just as the Manual explains it should be, yet I Keep getting the error. I have paisted the code in for reviewing below.
void main()
{
alert("wellcome to.", "cm blackjack, version 1.0");
}
string cards="card1, card2";
int card1=random(1, 10);
int card2=random(1, 10);
string message_string="Your two starting cards are " + card1 + " and " + card2 + ". hit okay to continue.";
alert("Your cards", message_string);

I used to be a knee like you, then I took an adventurer in the arrow.

2014-11-28 19:41:38

Try removing the right brace after your first welcome alert message and moving it to the end of the file. The right brace ended the main function. This confused the compiler, because the right brace ended the main function, but there was still code afterwards. Correct code pasted below:
void main()
{
alert("wellcome to.", "cm black jack, version 1.0");
string cards="card1, card2";
int card1=random(1, 10);
int card2=random(1, 10);
string message_string="Your two starting cards are " + card1 + " and " + card2 + ". hit okay to continue.";
alert("Your cards", message_string);
}

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

2014-11-29 14:12:47

okay, now for some reason alerts don't work any more, even when I coppy them from the Manuals. here is an alert I wroat.
alert("random alert", "you have been found guilty of having opened this alert and shall be terminated!");

I used to be a knee like you, then I took an adventurer in the arrow.

2014-11-29 14:33:13

Hi,

I recommend at least declaring all those variables higher up in the function, before you do anything else. You can declare them there as well but that's not strictly necessary.
What doesn't work about your alerts, do they not fire or do you get an error?

2014-11-29 15:33:20

The alert syntax you have written seems to be correct, so the error possibly could be in regards to another area of your code. If you can't find the problem, try posting the entire file again for assistance (if it isn't too large of course). smile

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

2014-11-29 16:15:23

I get a compilation error when trying to write the alert. the error line and character it tells me match the line where the alert is.

I used to be a knee like you, then I took an adventurer in the arrow.

2014-11-30 19:29:02

If you are still working through the tutorial, I really don't think you should be trying a project of this size anyway. Have you considered how you're going to keep track of all the player's cards? Yes, it's possible to just add variables, like so:
int card3;
int card4;
But this is a bit of a mess. The situation here screams array. You will be able to add and subtract cards from the array with simple function calls, rather than having a bunch of unused variables allocated.
As to your alert error, can you post the entire code in which the alert is being called? The syntax above appears to be correct. My guess is you're missing a closing symbol or a semicolon above the alert and that the engine doesn't like you calling a function inside another like this. Errors dont' necessarily refer to the line in question; that's just how the engine perceives them.

Best Regards,
Hayden

2014-12-01 02:51:48

Is the error pointing to the alert, by chance, an unclosed string literal, or an expected ')' or ';'? You might have an open string somewhere above it, or something like that.

看過來!
"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-12-01 17:56:52 (edited by Dakonna 2014-12-01 18:01:45)

okay here is my code again. strangely I didn't modify anything in the alert sections, but it gave me these Errors.
code:
void main
{
alert("wellcome to.", "cm blackjack, version 1.0");
string cards="card1, card2";
int card1=random(1, 10);
int card2=random(1, 10);
string message_string="Your two starting cards are " + card1 + " and " + card2 + ". hit okay to continue.";
alert("Your cards", message_string);
errors:
File: F:\downloads\testing\cm blackjack\cm blackjack.bgt
On line: 3 (1)
Line: alert("wellcome to.", "cm blackjack, version 1.0");
Error: Expected one of: get, set, }

File: F:\downloads\testing\cm blackjack\cm blackjack.bgt
On line: 3 (1)
Line: alert("wellcome to.", "cm blackjack, version 1.0");
Error: Instead found 'alert'

File: F:\downloads\testing\cm blackjack\cm blackjack.bgt
On line: 8 (6)
Line: alert("Your cards", message_string);
Error: Expected identifier

File: F:\downloads\testing\cm blackjack\cm blackjack.bgt
On line: 8 (6)
Line: alert("Your cards", message_string);
Error: Instead found '('

I used to be a knee like you, then I took an adventurer in the arrow.

2014-12-01 18:33:42

You need to replace "void main" with "void main()".  You did it this way in post 1, but the parentheses seem to have gotten dropped.  Due to how parsers work, an error like that will cause them to give errors about other things; start there and then fix what is left.

My Blog
Twitter: @ajhicks1992

2014-12-01 20:39:32

hello, something completely different this time. there seems to be something wrong with my seperating of code blocks, but I have no idea what it is. please look at this code.
void main()
{
alert("welcome!", "rore! I am the infamous zombifier! cower before me!.");
alert("how to play", "this is a simple bop it stile game. hit the correct arrow key for the sound you here. if you get it wrong or if the time runs out, you lose.");
int answer = question("ready?", "are you ready to get munched? you will aventually!");
if(answer==0)
{
alert("uh...","who let the zombs out. oh... well doesn't look like this is working!");
}
if(answer==1)
{
alert("very good!", "lets go then.");
}
if(answer==2)
{
alert("who cares?", "does it look like I care? does it look like the zombs care? all they want is your flesh! you can quit by hitting exit or escape anyway.. ready or not, here they come!");
}
show_game_window("zombie attack");
dynamic_menu menu;
menu.add_item_tts("release the zombies!");
menu.add_item_tts("shooting practice");
menu.add_item_tts("exit arena");
menu.allow_escape = true;
menu.wrap = true;
menu.run("main menu.", true);
}

I used to be a knee like you, then I took an adventurer in the arrow.

2014-12-01 23:18:18

I don't know.  You're not saying what is wrong with the code, only that it is, in some way, not doing what you want.  It looks syntactically right and I would expect it to compile though possibly with an error somewhere that I'm not catching.

My Blog
Twitter: @ajhicks1992

2014-12-02 00:38:42

It works fine for me, if I add #include "dynamic_menu.bgt" to the top.
It exits after the menu, but that appears to be expected.

看過來!
"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-12-02 15:14:55

I know, there's no code after the menu. this is to follow. I figured out that I Need to add the include function at the top, thanks anyway.

I used to be a knee like you, then I took an adventurer in the arrow.

2014-12-04 17:17:25

oh and just so you guys know, the code I posted on here is actually not for any games I am planning to make, at least not very soon. once I fully get the Hang of programming, I might release them.

I used to be a knee like you, then I took an adventurer in the arrow.

2014-12-21 14:18:18

hello, untill now I've taken a break from learning how to code, but now i've started again. I've written a peace of code I can't seem to run. It Looks correct to me, if anyone more experienced can please provide some advice on this code?
void main()
{
int awesomeness=100;
random_function(awesomeness);
alert("hey!", "I got something to say. I'm so awesome, my awesomeness is aproaching... " + awesomeness + "!");
}

I used to be a knee like you, then I took an adventurer in the arrow.

2014-12-21 16:59:20

alert("hey!", "I got something to say. I'm so awesome, my awesomeness is aproaching... " + awesomeness + "!");
Don't put the quotes around the comma after hey, i.e leave it in the string. Also, what is the implementation of random_function?

2014-12-21 22:45:33

hmm, why'd you just ask me that? just curious.

I used to be a knee like you, then I took an adventurer in the arrow.

2014-12-21 23:11:06

I believe he is asking where is random function declared? In that code, there is no function entitled random_function()

2014-12-22 17:42:26

I know, I never wanted to put it in.

I used to be a knee like you, then I took an adventurer in the arrow.

2014-12-22 22:41:09

That code won't compile or run unless you define the random_function() function.

2015-01-26 18:35:17

hello, I've been writing the code for a small program that checks the Sound devices installed on the user's Computer. ist basicly set up to make the user go through a really annoying set of alert Messages untill the actual function for finding the Sound devices is declaired. something's wrong with the code though, and i can't figure out what.
void main()
{
list_sound_devices()
alert("alert.", "booting sound device detecter...");
alert("success.", "lister booted. checking for errors in lister functions...");
alert("no errors found.", "dialog successfully displayed a.k.a. no errors with the system. searching for sound devices on this machine...");
alert("sound devices located.", "locking on...");
alert("lock successfull and holding.", "downloading data from devices now...")";
alert("data downloaded and stored.", "displaying...");
alert("sound devices.", "your sound devices are: list_sound_devices().");
}

I used to be a knee like you, then I took an adventurer in the arrow.

2015-01-26 19:57:59

Missing semicolon on the third line.  Missing definition of list_sound_devices, so even if you fix that it's still not going to compile.
Also, posting any error messages you get along with the program you're asking us to look over is a really, really big help in many cases.

My Blog
Twitter: @ajhicks1992

2015-01-26 22:58:56

And, doesn't list_sound_devices return a string array? I don't remember if BGT can concatenate those to strings natively.

If it doesn't, this function is most of the work:

string arraystring(string[] str) {
string ret="[";
for(uint i=0; i<str.length(); i++) {
ret += str[i];
if(i<str.length()-1) ret += ", ";
}
return ret + "]";
}
看過來!
"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.