我有一个全局变量号,因此它获得了一个函数的传递,但是当它完成时,它应该在函数内部更改该变量并将其传递到外部全局变量进行更新。因此,它继续使用旧的全局变量,而其他一切都在更新并变得更大。
var P_Level = 1
var E_Level = 1
var P_Current = 0
var P_Max = 100
function P_EXP_Gain(exp) {
console.log('P_Max1 is '+P_Max)
console.log('P_Current1 is '+P_Current)
console.log('P_Level1 is '+P_Level)
console.log("")
if (exp == undefined || null) {
P_Current = (E_Level * 20) + P_Current
P_Max = P_Max
P_Experience(P_Current, P_Max)
}
else {
P_Current = ((E_Level * 20) + exp) + P_Current
P_Max = P_Max
console.log('P_Max2 is '+P_Max)
console.log('P_Current2 is '+P_Current)
console.log('P_Level2 is '+P_Level)
console.log("")
P_Experience(P_Current, P_Max)
}
}
function P_Experience(P_Current, P_Max) {
while (P_Current >= P_Max) {
P_Level++ // There is a hidden error that causes one to gain perm level up every time they level up via normal way.
P_Current = P_Current - P_Max
P_Max = P_Level * 100
console.log("")
console.log('P_Max3 is '+P_Max)
console.log('P_Current3 is '+P_Current)
console.log('P_Level3 is '+P_Level)
console.log("")
alert('Level Up')
}
}
P_EXP_Gain(80)
P_EXP_Gain(80) // notice that current random get extra 100
P_EXP_Gain(80)
您可以通过 console.log 看到,在 while 循环之前,它的 P_Max 始终为 100,但在那之后,它会正确更改,但该更改永远不会更新为全局 P_Max。我还注意到,在第一个 P_EXP_Gain 之后,在考虑增益之前,函数第一部分中的 P_current 将增加 100。我不知道为什么会发生这种情况。我是不是数学哪里搞错了?
https://jsfiddle.net/Necrorifter/Lc18tobw/9/
白板的微信
慕码人8056858
相关分类