Почему может возникнуть ошибка Error: expected Number, если я преобразую переменную в тип Number?
Item = Number(Item);
Если попробовать вывести тип, то тоже выводится Number
alert('${typeof(Item)}')
Весь код:
let browser;
const Data = require("creator/data");
const creatorCoords = {
camera: new mp.Vector3(402.8664, -997.5515, -98.5),
cameraLookAt: new mp.Vector3(402.8664, -996.4108, -98.5)
};
const localPlayer = mp.players.local
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function updateParents() {
localPlayer.setHeadBlendData(
Data.mothers[Item],
Data.fathers[Item2],
0,
// skin
Data.mothers[Item],
Data.fathers[Item2],
0,
// mixes
similarityItem * 0.01,
skinSimilarityItem * 0.01,
0.0,
false
);
}
function setMale() {
localPlayer.model = mp.game.joaat('mp_m_freemode_01');
localPlayer.setDefaultComponentVariation();
localPlayer.setComponentVariation(3, 15, 0, 2);
localPlayer.setComponentVariation(4, 0, 0, 2);
localPlayer.setComponentVariation(6, 34, 0, 2);
localPlayer.setComponentVariation(8, 15, 0, 2);
localPlayer.setComponentVariation(11, 15, 0, 2);
}
function setFemale() { // в зависимости от кол-ва использований перенести из функци или объеденить с фун выше
localPlayer.model = mp.game.joaat('mp_f_freemode_01');
localPlayer.setDefaultComponentVariation();
localPlayer.setComponentVariation(3, 15, 0, 2);
localPlayer.setComponentVariation(4, 0, 0, 2);
localPlayer.setComponentVariation(6, 35, 0, 2);
localPlayer.setComponentVariation(8, 15, 0, 2);
localPlayer.setComponentVariation(11, 15, 0, 2);
}
mp.events.add("create", () => {
creatorCamera = mp.cameras.new("creatorCamera", creatorCoords.camera, new mp.Vector3(0, 0, 0), 45);
creatorCamera.pointAtCoord(402.8664, -996.4108, -98.5);
creatorCamera.setActive(true);
mp.game.cam.renderScriptCams(true, false, 0, true, false);
mp.gui.chat.show(false);
mp.game.ui.displayRadar(false);
mp.game.ui.displayHud(false);
localPlayer.clearTasksImmediately();
localPlayer.freezePosition(true);
setMale()
browser = mp.browsers.new('package://creator/index.html');
//browser.execute(`alert(${localPlayer.isMale()})`);
setTimeout(() => {
mp.gui.cursor.show(true, true);
}, 500);
});
mp.events.add("changeGender", (state) => {
//state == true ? mp.game.joaat('mp_m_freemode_01') : mp.game.joaat('mp_f_freemode_01');
if (state == true) setMale();
else setFemale();
});
// CREATOR PARENTS
//let similarities = [];
let Item = 0;
let Item2 = 21;
let similarityItem = 50;
let skinSimilarityItem = 50;
mp.events.add("setMother", (x) => {
//let type = typeof(x);
Item = 25;
//browser.execute(`alert('${Item}')`);
//browser.execute(`alert('${typeof(Item)}')`);
//Item = Number(Item);
//Item = parseInt(Item);
//browser.execute(`alert('${typeof(Item)}')`);
updateParents();
});
mp.events.add("setFather", (x) => {
//fatherItem = x;
//updateParents();
});
mp.events.add("setSimilarity", (x) => {
similarityItem = x;
updateParents();
});
mp.events.add("setSkinSimilarity", (x) => {
skinSimilarityItem = x;
updateParents();
});
mp.events.add("parentsRandom", () => {
fatherItem = getRandomInt(0, Data.fathers.length - 1);
motherItem = getRandomInt(0, Data.mothers.length - 1);
similarityItem = getRandomInt(0, 100);
skinSimilarityItem = getRandomInt(0, 100);
updateParents();
browser.execute(`alert('f: ${fatherItem}, m: ${motherItem}, s1: ${similarityItem}, s2: ${skinSimilarityItem}')`);
});
// CREATOR PARENTS END
mp.events.add("setTurn", (degree) => {
localPlayer.setHeading(parseFloat(degree));
});
mp.events.add("closeC", () => {
browser.destroy();
mp.gui.cursor.show(false, false);
mp.gui.chat.show(true);
mp.game.ui.displayRadar(true);
mp.game.ui.displayHud(true);
localPlayer.freezePosition(false);
//localPlayer.setDefaultComponentVariation();
//localPlayer.setComponentVariation(2, Data.hairList[currentGender][hairItem.Index].ID, 0, 2);
mp.game.cam.renderScriptCams(false, false, 0, true, false);
});