2017-01-26 4 views
0

Ich mache ein Spiel und füge ein Tutorial hinzu. Ich habe versucht, eine Verbindung zu den "Rezepten" herzustellen, wie ich es Website nenne, aber es lief jeden Tag aus. Um das zu lösen, öffnete ich ein neues Fenster mit Inhalten darin. Das einzige Problem ist, dass dosent korrekt funktioniert. Wenn ich das Fenster öffne, scheint es sich zweimal zu wiederholen. Im folgenden Codebeispiel habe ich es so formatiert, dass es leichter zu lesen ist, als wenn es alles in einer Zeile wäre. Vielen Dank für Ihre Hilfeneues Fenster wird nicht korrekt geladen

function newWindow() { 
 
\t myWindow = window.open("", "myWindow", "width=900,height=500"); 
 
\t myWindow.document.write("<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<title> RSS Earth Recipies</title> 
 
<style> 
 
body{ 
 
\t background-color: #f4dc42; 
 
} 
 
</style> 
 
</head> 
 
<body> 
 
<p> 
 
<h3>Shop:</h3> 
 
<br>Fire = 5 Wood<br> 
 
Lumber Jack = 10 Fire and consumes one fire and water per second<br> 
 
House = 50 Wood and 50 Fire<br> 
 
Furnace = 30 Wood and takes one Wood to output on fire<br> 
 
Soldier x 10 = -1 Barracks, 10 water and food and consumes 1 food and water per second<br> 
 
Barracks = 10 houses <br> 
 
Wells = 20 Wood and 5 Food and consumes 1 Food per second but outputs 2 Water per second <br> 
 
Hunter = 10 Wood and 5 Water and consumes 1 Water per second but outputs 2 Food per second<br> 
 
Breeders = 1 house and consumes 1 Fire, Water, and Food per second<br> 
 
<h3>In case you didn't know</h3> 
 
<br><ul> 
 
<li>Every 30 minutes barbarians will raid your civilization and every hour a nation will sweep your civilization.</li> 
 
<li>The number of barbarians can list from 1 to 1000 but for the nation it can go from 1 to 1 Million</li> 
 
<li>This versoin of the game's <b>DESIGN</b> was only made for the 1:1 student laptops that were distributed by onslow conty schools</li> 
 
<li>If you press F12 then you will find various things in the inspector</li> 
 
<li>Press the '/' key and help will pop up</li> 
 
</ul> 
 
</p> 
 
<br> 
 
<hr> 
 
<h1>Tutorial:</h1> 
 
<br> 
 
<ol> 
 
<li>To start things off The first thing you should do is collect wood. You can do this by either pressing the 'Collect Wood' button at the bottom of the webpage or by pressing the 'w' key</li> 
 
<li>Collect at least 30 wood to continue</li> 
 
<li>When you have this collect 30 of both Food and Water. You can do this by pressing the 'Collect Food' and 'Collect Water' buttons at the bottom of the webpage or by pressing the 'q' key for water and the 'o' key for food.</li><li>Now that you have this, we can begin 'automated production' as i like to call it. Quickly press the 'Build Well' and 'Train Hunter' buttons at the bottom of the webpage <b>ONCE</b>. Now your civilization is off to a good start!</li> 
 
<li>When your feeling kind of lost again turn your wood into fire. Remember 5 wood will give you 1 fire.</li><li>So you have that now when you collect 5 fire just go ahead and press the 'Train Lumber Jack' at the bottom of the webpage. Remember: a Lumber Jack will take up 1 food and water per second</li><li>Next when your ready, make sure you have 30 wood and buy a furnace. You can do this by pressing the 'Make Furnace' button at the bottom of the webpage. This will output one fire per second and will destroy one wood per second</li><li>Moving on to houses and barracks. A house will do good for you if you want to get breeders but their also good if you want to train an army. Houses can be converted into barrack if you have the right amount. In order to make a house you have to have 50 wood and fire.</li> 
 
<li>The only reason Barracks are in the game is for the soldiers. Cant have an army with out a storage unit can you? Anyway thats basically the only reasoning you have Barracks. When you buy soldiers you will destroy the amount of Barracks nessesary in order to get troops</li><li>The deal with troops is to give your town a defence against Barbarians, nations, continents, and soon other players! But having troops comes with a cost. The lowest amount of troops you can train at one time is 10 and being that each one accounts for taking in 1 food and water per second your going to need a lot of food and water production!</li> 
 
<li>Now were near the end of the tutorial. This last segment will be about Breeders. Breeders are used for population. Population is shown just above the earth right under the season stats. The reason why these are so useful is because you can convert your current population to either Lumber Jacks or Soldiers. Now in order to convert Population into Soldiers you will need to have at least one Barrack in town. Also keep in mind that the amount that you convert is the amount you have to provide for... Resource wise.</li><h3>Thank you for reading the tutorial! Best of luck!</h3><hr><br><h4><i>Liam Sperry</i></ol></body></html> 
 
}
<a onclick="newWindow()">view recipies</a>

+1

theres keine direkten mehrzeiligen JavaScript-String-Literale. –

Antwort

1

können Sie dies versuchen und lassen Sie es mich wissen, wenn es funktioniert.

function newWindow() { 
    myWindow = window.open("", "myWindow", "width=900,height=500"); 
    myWindow.document.write("<!DOCTYPE html><html><head><title> RSS Earth Recipies</title><style>body{ background-color: #f4dc42;}</style></head><body><p><h3>Shop:</h3><br>Fire = 5 Wood<br> Lumber Jack = 10 Fire and consumes one fire and water per second<br> House = 50 Wood and 50 Fire<br> Furnace = 30 Wood and takes one Wood to output on fire<br>Soldier x 10 = -1 Barracks, 10 water and food and consumes 1 food and water per second<br>Barracks = 10 houses <br> Wells = 20 Wood and 5 Food and consumes 1 Food per second but outputs 2 Water per second <br> Hunter = 10 Wood and 5 Water and consumes 1 Water per second but outputs 2 Food per second<br>Breeders = 1 house and consumes 1 Fire, Water, and Food per second<br><h3>In case you didn't know</h3><br><ul><li>Every 30 minutes barbarians will raid your civilization and every hour a nation will sweep your civilization.</li><li>The number of barbarians can list from 1 to 1000 but for the nation it can go from 1 to 1 Million</li><li>This versoin of the game's <b>DESIGN</b> was only made for the 1:1 student laptops that were distributed by onslow conty schools</li><li>If you press F12 then you will find various things in the inspector</li><li>Press the '/' key and help will pop up</li></ul></p><br><hr><h1>Tutorial:</h1><br><ol><li>To start things off The first thing you should do is collect wood. You can do this by either pressing the 'Collect Wood' button at the bottom of the webpage or by pressing the 'w' key</li><li>Collect at least 30 wood to continue</li><li>When you have this collect 30 of both Food and Water. You can do this by pressing the 'Collect Food' and 'Collect Water' buttons at the bottom of the webpage or by pressing the 'q' key for water and the 'o' key for food.</li><li>Now that you have this, we can begin 'automated production' as i like to call it. Quickly press the 'Build Well' and 'Train Hunter' buttons at the bottom of the webpage <b>ONCE</b>. Now your civilization is off to a good start!</li><li>When your feeling kind of lost again turn your wood into fire. Remember 5 wood will give you 1 fire.</li><li>So you have that now when you collect 5 fire just go ahead and press the 'Train Lumber Jack' at the bottom of the webpage. Remember: a Lumber Jack will take up 1 food and water per second</li><li>Next when your ready, make sure you have 30 wood and buy a furnace. You can do this by pressing the 'Make Furnace' button at the bottom of the webpage. This will output one fire per second and will destroy one wood per second</li><li>Moving on to houses and barracks. A house will do good for you if you want to get breeders but their also good if you want to train an army. Houses can be converted into barrack if you have the right amount. In order to make a house you have to have 50 wood and fire.</li><li>The only reason Barracks are in the game is for the soldiers. Cant have an army with out a storage unit can you? Anyway thats basically the only reasoning you have Barracks. When you buy soldiers you will destroy the amount of Barracks nessesary in order to get troops</li><li>The deal with troops is to give your town a defence against Barbarians, nations, continents, and soon other players! But having troops comes with a cost. The lowest amount of troops you can train at one time is 10 and being that each one accounts for taking in 1 food and water per second your going to need a lot of food and water production!</li><li>Now were near the end of the tutorial. This last segment will be about Breeders. Breeders are used for population. Population is shown just above the earth right under the season stats. The reason why these are so useful is because you can convert your current population to either Lumber Jacks or Soldiers. Now in order to convert Population into Soldiers you will need to have at least one Barrack in town. Also keep in mind that the amount that you convert is the amount you have to provide for... Resource wise.</li><h3>Thank you for reading the tutorial! Best of luck!</h3><hr><br><h4><i>Liam Sperry</i></ol></body></html>" 
} 

Ich lösche nur die Leerzeichen und die Eingabe wird verwendet. Es funktioniert jetzt. Sie können nicht in einer Zeichenfolge wie folgt eingeben:

var string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque quis eros lorem. Quisque eu ultricies nunc, et fermentum dui. Integer quis elementum nunc. Nullam a tempus nibh. // just entered here 
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aliquam rutrum tristique tincidunt. Fusce mollis scelerisque mauris, non porttitor est egestas sed. Curabitur elementum, augue nec finibus tincidunt, nunc leo fermentum sapien, quis lobortis enim nunc at justo." 

wenn Sie eine Zeichenfolge wie diese haben und u wollen, dass es auf diese Weise verwenden u + innerhalb von Zeichenketten wie diese verwenden:

var string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque quis eros lorem. Quisque eu ultricies nunc, et fermentum dui. Integer quis elementum nunc. Nullam a tempus nibh."+ 
     "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aliquam rutrum tristique tincidunt. Fusce mollis scelerisque mauris, non porttitor est egestas sed. Curabitur elementum, augue nec finibus tincidunt, nunc leo fermentum sapien, quis lobortis enim nunc at justo."; 

Hoffnung das wird helfen :)

+0

Vielen Dank für Ihre Hilfe! Es gab viel Verwirrung mit meinem Spiel, also brauchte ich wirklich dieses lol. Aber nochmal vielen Dank! –

+0

Kein Problem, wenn Sie zukünftige Hilfe benötigen, lassen Sie es mich wissen :) –

0

Verwendung innerHTML stattdessen die HTML statt zu schreiben, was auch immer ist es bereits zu überschreiben.

Verwandte Themen