I am trying to convert this expression here into gd script.

This is what I have:

(1/8)(pow(level,2)-level+600((pow(level,(level/7))-pow(2,(1/7)))/((pow(2,(1/7))-1))))

but the answer i'm getting is the max -int (-9223372036854775800)

The answer if i plug in 50 should be 101339.026949

  • (1/8)(pow(level,2)-level+600((pow(level,(level/7))-pow(2,(1/7)))/((pow(2,(1/7))-1))))
    should be:
    (1.0/8.0)(pow(level,2.0)-level+600.0((pow(2.0,(level/7.0))-pow(2.0,(1.0/7.0)))/((pow(2.0,(1.0/7.0))-1.0))))

    Note that I added decimal points to all the numbers. Mixing integer and floating point operations is tricky, so it's safest to avoid that. And 1/8 is 0, while 1.0/8.0 is 0.125. Also, ensure that level is declared as float.

    If that doesn't fix it, please post your GDScript code.

(1/8)(pow(level,2)-level+600((pow(level,(level/7))-pow(2,(1/7)))/((pow(2,(1/7))-1))))
should be:
(1.0/8.0)(pow(level,2.0)-level+600.0((pow(2.0,(level/7.0))-pow(2.0,(1.0/7.0)))/((pow(2.0,(1.0/7.0))-1.0))))

Note that I added decimal points to all the numbers. Mixing integer and floating point operations is tricky, so it's safest to avoid that. And 1/8 is 0, while 1.0/8.0 is 0.125. Also, ensure that level is declared as float.

If that doesn't fix it, please post your GDScript code.

    DaveTheCoder

    I was returning an int on a float value so I solved that problem but now I'm getting NAN for the following code.

    extends Resource
    class_name SkillData
    
    @export var name: String
    @export_multiline var description: String = ""
    @export var texture: AtlasTexture
    @export var level: int = 1
    @export var level_progress: int = 0
    @export var xp_needed_to_level: float
    
    
    func set_variables(_level : int) -> float:
    	var val: float = (1/8)*(pow(level,2)-level+600*((pow(level,(level/7))-pow(2,(1/7)))/((pow(2,(1/7))-1))))
    	return val

    I can add more but theres quite a few layers to get to where I am implementing this function. Which means somewhere im dividing by 0 or my numbers are too small i think?

    DaveTheCoder

    This worked! thank you so much! Just as a little knowledge that i found out while doing this, putting a number directly next to parentheses makes gdscript think that it is a callable. Have to put a * in there for those cases.