Aido
Aido

Reputation: 1584

html onload not running javascript

I'm writing a game in javascript, and I had the world generator running fine, but when I created a startup function to run multiple things at once, my code doesn't run at all anymore. Can anyone see my problem?

<head>
<title>Project Rust</title>
<!-- <link href="/YOUR_PATH/favicon.ico" rel="icon" type="image/x-icon" /> -->
<script src="Scripts/startup.js"></script>
<script src="Scripts/drawmap.js"></script>
<script src="Scripts/maps.js"></script>
<script src="Scripts/mapread.js"></script>
<script src="Scripts/mainchar.js"></script>
</head>
<body bgcolor="#BFE3FF" onload="startup()">
</body>

startup.js: startup(){ alert("start"); drawmap(Screen[0]); mainchar(); }

Upvotes: 0

Views: 2181

Answers (3)

Hazem Salama
Hazem Salama

Reputation: 15121

You are missing the function declaration in your startup.js

You need function startup(){ /*your code*/ }

Upvotes: 0

alf
alf

Reputation: 18550

You should set the type to the script tags:

<script type="text/javascript" src="Scripts/startup.js"></script>

Also, you need to use the function keyword to define a function in javascript:

function startup(){
  alert("start");
  drawmap(Screen[0]);
  mainchar();
}

If it's still now working, open your browser's javascript console and you should see the error.

Upvotes: 0

Danilo Valente
Danilo Valente

Reputation: 11352

Try this:

function startup(){
    alert("start"); drawmap(Screen[0]); mainchar();
}

Upvotes: 1

Related Questions