如何解决如何通过多个函数传递值
这是我的示例项目列表和更新项目方法(后来导入“更新为更新项目”)
export const itemsForest = [
{
x: 3,y: 3,mainTexture: "house.png",interaction: function(){
console.log("enterHouse");
}
},{
x: 4,y: 4,mainTexture: "letter.png",interaction: function(){
console.log("test");
}
},{
x: 3,y: 8,mainTexture: "exitForest.png",interaction: function(){
return {changeMap: true,map: mapIsland,items: itemsIsland,playerPos: {x: 3,y: 8}};
}
}
]
export function update(currentItems){
for(const item of currentItems){
if(underCharacter(item)){
item.interaction();
}
}
}
function update(){
updateCharacter(currentMap);
if(updateItems(currentItems).changeMap === true){
currentMap = updateItems(currentItems).map;
currentItems = updateItems(currentItems).items;
}else{
updateItems(currentItems);
}
}
真的不知道如何将交互返回的内容传递给更新 我也尝试返回 item.interaction() 但它没有帮助 也许有更好的方法,我需要更改其他文件中的变量:
let currentMap = mapIsland;
let currentItems = itemsIsland;
const entitiesBoard = document.querySelector("#entitiesBoard");
function main(currentTime){
if(gameOver){
return alert("You Lose");
}
// window.requestAnimationFrame(main);
const secondsSinceLastRender = (currentTime - lastRenderTime)/1000;
if(secondsSinceLastRender < 1 / gameSpeed) return;
lastRenderTime = currentTime;
update();
draw();
}
事情是 IM 收到错误:
Uncaught TypeError: Cannot read property 'changeMap' of undefined
at update (game.js:51)
at main (game.js:36)
at game.js:41
如果有人可以提供帮助,我会很高兴也向我解释为什么这种方式而不是另一种方式
总而言之:我想要这样的东西:
function a{
return {1}
}
export function b{
function a()
}
import function b;
function c{
//Get Somehow function a value
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。