Hello, please keep in mind that I am a beginner programmer with almost no prior knowledge. thanks :)
Using my save system I am trying to edit the player's jump value. I am saving the int correctly because it is coming out correctly in the Output, but the int is not affecting the player's jump. I would appreciate any help that can be directed my way. Here is the code:
Player.gd:
extends KinematicBody2D
var SPEED = 500
var MAXSPEED = 150
var FRICTION = .5
var resistance = 0.7
var grav = 500
var jump = Save.jump
var vel = Vector2.ZERO
var spring = -400
var jumpNumber = 2
var MAXFALLSPEED = 500
var is_grounded
signal killed()
signal healthUpdated(health)
var MAXHEALTH = GlobalVars.MAXHEALTH
onready var InvTimer = $InvFrames
onready var health = MAXHEALTH setget setHealth
onready var sprite = $Sprite
onready var animEffects = $Effects
onready var anim = $moveAnimations
func ready():
health = MAXHEALTH
emitsignal("healthUpdated", health)
func physicsprocess(delta):
#left-right movement
var movementx = Input.getactionstrength("uiright") - Input.getactionstrength("uileft")
if movementx != 0:
vel.x += movementx * SPEED * delta
vel.x = clamp(vel.x, -MAXSPEED, MAXSPEED)
if Input.isactionpressed("uiright") and isonfloor():
anim.play("Run")
if Input.isactionpressed("uileft") and isonfloor():
anim.play("Run")
sprite.fliph = movement_x > 0
#for bullet rotation direction
if sprite.flip_h == true:
Signals.l = true
if sprite.flip_h == false:
Signals.l = false
if is_on_floor():
Signals.onground = true
if movement_x == 0:
vel.x = lerp(vel.x, 0, FRICTION)
anim.play("Idle")
if Input.is_action_just_pressed("jump"):
vel.y -= jump
if !is_on_floor():
Signals.onground = false
if vel.y < 0:
anim.play("Jump")
if vel.y > 0:
anim.play("Fall")
vel.y += grav * delta
if vel.y > MAXFALLSPEED:
vel.y = MAXFALLSPEED
vel = move_and_slide(vel, Vector2.UP)
func onSpringbodyentered(_body):
vel.y = spring
anim.play("Jump")
func onKillBoxbodyentered(body):
Signals.emitsignal("playerDeath")
return
#shooting
onready var plbullet = preload("res://BulletPlayer.tscn")
onready var firePosition = $firePosition
func process(delta):
if Input.isactionjustpressed("shoot"):
var Bullet = plbullet.instance()
Bullet.globalposition = firePosition.globalposition
gettree().currentscene.addchild(Bullet)
func setHealth(value):
var prevHealth = health
health = clamp(value, 0, MAXHEALTH)
if health != prevHealth:
emitsignal("healthUpdated", health)
if health == 0:
kill()
Signals.emitsignal("playerDeath")
func kill():
print("ubad")
func damage(amount):
if InvTimer.is_stopped():
InvTimer.start()
setHealth(health - amount)
animEffects.play("Damage")
animEffects.queue("Inv")
func onInvFrames_timeout():
animEffects.play("Rest")
And the Save.gd (which is a autoload):
extends Node
var jump = 350
onready var player = preload("res://Player/Player.tscn").instance()
#for when I used player vars directly
var file_path = "user://save.txt"
func _ready():
_load()
print(jump)
func save():
var data = ""
data += "maxheath " + str(GlobalVars.MAXHEALTH)
data += "\n"
data += "jump " + str(jump)
var newfile = File.new()
newfile.open(filepath, File.WRITE)
newfile.storeline(data)
new_file.close()
print("saved")
func load():
var newfile = File.new()
if not newfile.fileexists(filepath):
_save()
return
newfile.open(filepath, File.READ)
var data = newfile.getastext()
newfile.close()
data = data.split("\n")
for line in data:
if line.beginswith("maxhealth "):
GlobalVars.MAXHEALTH = int(line.split(" ")[1])
elif line.begins_with("jump "):
jump = int(line.split(" ")[1])