Hello! I’m new to game developing on this engine and am having some problems. While most of them I were able to solve with internet, I couldn’t find a solution to this issue that works for me.
Here’s the script that tries to call a function:
extends Node2D
@onready var itemWeapon = $ItemWeapon
var weapon_pistol = ["Pistol", "pistol", 1, 0.3, 5, "pistol", 3, 30, 1, 5, 10, 1000, 0, 10, 0, 0]
func create_weapon(w):
itemWeapon.create_weapon(w[0], w[1], w[2], w[3], w[4], w[5], w[6], w[7], w[8], w[9], w[10], w[11], w[12], w[13], w[14], w[15])
Here’s the ItemWeapon script, which belongs to child node of the first
extends Node2D
class_name ItemWeapon
var WeaponName: String #name of a weapon
var WeaponType: String #type(pistol, rifle, etc)
var ShootsBullet: int #whether or not spawns bullets
var FireRate: float #delay between shots in seconds
var AmmoMag: int #shots before reload
var AmmoType: String #type of ammo used
var ReloadTime: float #delay in seconds
var Damage: float #damage on hit
var Multishot: int #amount of bullets per shot
var Spread: int #spread in degrees
var MultishotSpread: int #spread in degrees
var BulletSpeed: int #speed of bullet
var CurrentAmmo: int #ONLY USED WHEN IN HAND
var TimeRange: float #Time in seconds before bullet dies
var BulletBounce: int #How many times will bounce
var BulletPenetration: int #How many times will penetrate
func create_weapon
(weaponName:String,
weaponType:String,
shootsBullet:int,
fireRate:float,
ammoMag:int,
ammoType: String,
reloadTime:float,
damage:float,
multishot:int,
spread:int,
multishotSpread:int,
bulletSpeed:int,
currentAmmo:int,
timeRange:float,
bulletBounce:int,
bulletPenetration:int):
var newWeapon = ItemWeapon.new()
newWeapon.WeaponName = weaponName
newWeapon.weaponType = weaponType
newWeapon.ShootsBullet = shootsBullet
newWeapon.FireRate = fireRate
newWeapon.AmmoMag = ammoMag
newWeapon.AmmoType = ammoType
newWeapon.ReloadTime = reloadTime
newWeapon.Damage = damage
newWeapon.Multishot = multishot
newWeapon.Spread = spread
newWeapon.MultishotSpread = multishotSpread
newWeapon.BulletSpeed = bulletSpeed
newWeapon.CurrentAmmo = currentAmmo
newWeapon.TimeRange = timeRange
newWeapon.BulletBounce = bulletBounce
newWeapon.BulletPenetration = bulletPenetration
return newWeapon
I know this is not the most elegant style of writing. It works for me in other cases