怎么在另一个脚本里调用本脚本里的一个方法

新手一只,用module.exports调用函数和变量都能调用,但是一调用方法就报错,怎么正确调用呢?

按道理应该都可以调用,报了什么错?

你是不是没有new,直接就调了?

is not a function

new了,报错is not a function

show us your code
把代码贴一下

这是代码

这是代码

第二张图片里的 js.zcth

js好像并没有new出来

前面加个 newJs = new js 试试

唔 new应该是有的 module.exports 那里new了一个

我没有试过这样写2333 通常我是直接module.exports一个普通的对象出来。 然后调用里面的东西。像这样直接实例化一个继承自cc.Component的cc.Class作为组件并调用里面的方法确实有点让人一脸蒙蔽。不依附于节点的组件和咸鱼有啥区别?anyway,我回头去试试怎么做,不过实例化组件缺不将它依附于节点上,确实有点让人摸不着头脑。

那有什么方法可以在另外一个脚本里修改这个组件的属性呢

同一份脚本通过挂载到同一个或者不同的节点上可以实例化出多个代码相同,参数不一定相同的组件,通过代码修改另一个组件的属性,首先需要拿到对方的节点或者组件,再进行修改。

cc.Class({
extends: cc.Component,

properites: {
 //solution one :get the reference of the component directly
  othreComponent: require('other-conponent-file-name'),
 //solution two :get the reference of the node first and get the component next.
 otherNode : cc.Node,
},

onLoad: function(){
  let oneWayToGetTheRef = this.otherComponent;
  let anotherWayToGetTheRef = this.otherNode.getComponent('other-component-file-name');
}
});