简体   繁体   English

为什么我的代码不能与球员的目标工作?

[英]Why does my code not work with a player object?

I added a player object for save games to my "game" (aka me learning JS), but it seems that the game is not working anymore because of it. 我添加了保存游戏我的“游戏”玩家对象(也就是我学习JS),但似乎游戏不工作了的缘故吧。

http://jsfiddle.net/TieSoul/Jjmdv/10/ http://jsfiddle.net/TieSoul/Jjmdv/10/

player = {}

and all related things seem to make it non-functional even though it should still work afaik. 并且所有相关的事情似乎使它无法运行,即使它仍然可以正常运行。

You have some other issues too in your code but.. add this: 你有一些其他的问题太在你的代码,但..补充一点:

player.player = {};

Like: 喜欢:

var player = {};
player.cookies = 0;
player.cookieIncrement = 1;
player.buildingsArr = [0];
player.player = {}; //HERE
player.player.buildingsCost = [10];
player.player.buildingsForEvery = [1];
player.buildingsName = ['Cursors'];
player.cursUpgrGet = [0, 0];
player.cursUpgrCost = [50, 200];
player.upgradeAmnt = [2];
player.fps = 60;
player.cps = 0;

Also try using some javascript consoles while coding like firebug. 也可以尝试使用一些JavaScript控制台,而编码像萤火虫。

I think there are quite a few errors, I am not sure what you want to fix. 我认为有相当多的错误,我不知道你想解决什么。

I replaced, in the html part of the jsfiddle: 我更换,在的jsfiddle的HTML部分:

var e = document.getElementById("player.cookies");

by: 通过:

var e = document.getElementById("cookies");

Basically you have a document.getElementById('player.cookies') but you can not find it because the element with id player.cookies doesnt exist. 基本上,你有一个的document.getElementById(“player.cookies”),但你不能找到它,因为有犯规存在ID player.cookies的元素。

And you can see the cookies made. 您可以看到制作的cookie。

Basically you tried to modify the innerHTML of a non existing element (player.cookies). 基本上你试图修改不存在的元素(player.cookies)的innerHTML。

I also changed: 我也改变了:

player.player.buildingsCost = [10];
player.player.buildingsForEvery = [1];

by: 通过:

player.buildingsCost = [10];
player.buildingsForEvery = [1];

The jsfiddle with my changes to your code: 我对您的代码所做的更改的jsfiddle:

http://jsfiddle.net/Jjmdv/14/ http://jsfiddle.net/Jjmdv/14/

Note that now there is a counter for the cookies. 请注意,现在有一个cookie计数器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM