This Message Forum is no longer in use

Please use the new Bravenet Help Forums FOUND HERE

General Forum
This Forum is Locked
Author
Comment
problems with java code

I'm having problems getting this java code to work!







Re: problems with java code

There isn't any Java in the page you linked to (and no javascript either).

Re: problems with java code

sorry about the code not appearing!
the starting thing with script languege=java script can't be added or it won't show it.
part of the script will be in button form!

var q = 0
var question= 'nothing'
var anwser= 'nothing'
var anwser2= 'nothing'
if (q = 0){
question='you wake going down stairs to eat breakfast when the door bell rings what do you do?';
}
if (q = 1){
question='you eat breakfast';
}
if (q = 2){
question='you get the door bell';
}
if (q = 0){

anwser='Eat breakfast';
}
if (q = 1){
anwser='you ate breakfast';
}
if (q = 2){
anwser='you get the door bell';
}
if (q = 0){
anwser2='Get the door'
}
if (q = 1){
anwser2='you ate breakfast'
}
if (q = 2){
anwser2='you get the door bell'
}
document.write(question);
document.write();
document.write();

Re: problems with java code

It's always a bad idea to post mixed HTML and Javascript in the forum. It can be done, but it's a lot of work substituting characters, so the forum won't delete things. It is always a better idea to put the code on a test page, and give use the URL. It's much easier for us to view it.

It looks like the start of a maze type game, where the player selects answers to questions, and is then presented with other questions/answers, based on the answers they give. If that's really off base, explain a little bit about your intentions.

The first order of business is to get it to display anything at all. So I made some adjustments so that it would. But that's about all it does. I corrected the syntax, made the IF statements partially usable, and quoted things properly. I did not put any scripting in for the "onClick" functions, because, I really don't know what you want it to do, and you don't really have any functions to do anything. The code below will display the question and two answer buttons, but clicking on the buttons will not do anything.







Some of the changes I made are:


  • I removed the initial definitions for the variables. Since "q" is initialized to "0", the IF statements will initialize them, when the page loads.
  • Your IF statements were not IF statements. If you only use a single "=" in the IF statement, all you do is make a variable assignment. Use a double equal sign, "==", for a query.
  • I fixed the quoting in the "document.write" statements. If you want a quote character to be part of the write string, you need to preceed it with a escape character, "". You can sometimes switch between single and double quotes, to avoid the escape character, but there are may situations where that will not work. Properly quoting and escaping output data is often very tedious with dynamic code.


The IF statements all work, however they only operate once, when the page is loaded. Since "q" is set to "0" initially, only the "(q == 0)" statments are true and executed. The others, "(q == 1)" and "(q == 2)", are completely ignored, and can never be used again. If you want to make them usable the need to be included directly in the button event code, or wrapped in a function statement, and called from the button event code.

Give us a little more information on what your trying to do, and we may be able to go further.

Re: problems with java code

I'm trying to make a word/button game where you click on a button then something in the game happens! Like a interactive story where you chose the ending!

I need to make it when you click the buttons then q+1 or q+2 takes effect!