Brutile Posted February 7, 2016 Share Posted February 7, 2016 I have a script that grabs the player entity as a value: Script.player = nil --Entity "Player" The player gets assigned in the scene properties. This succeeds: if self.player ~= nil then end But this doesn't: if self.player.script ~= nil then end The player definitely has a script, and I've accessed the script the same way by passing it directly. But using the properties panel to set the player, it doesn't work. Quote Link to comment Share on other sites More sharing options...
macklebee Posted February 7, 2016 Share Posted February 7, 2016 Can you give more detail on your script? Have you checked the output log to see if it has loaded/executed the player's script prior to this script? I just tried this simple script on a csg box with the standard fpsplayer set as the 'script.player', and it seems to work. Script.player = nil --Entity "Player" function Script:Start() if self.player ~= nil then System:Print("player exists") end if self.player.script ~= nil then System:Print("script exists") end end Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Brutile Posted February 7, 2016 Author Share Posted February 7, 2016 This is the full script Script.player = nil --Entity "Player" Script.enemyPath = "" --path "Enemy Prefab" "Prefab (*.pfb):pfb|Prefabs" Script.spawnRate = 5 --float "Initial Spawn Rate" Script.spawnVariation = 0.25 --float "Spawn Variation" Script.spawnAmount = 5 --int "Initial Spawn Amount" Script.spawnTimer = 0 function Script:Start() self.spawnTimer = self.spawnRate end function Script:UpdateWorld() local deltaTime = (1.0 / Time:UPS()) if self.spawnTimer <= 0 and self.spawnAmount > 0 then self.spawnTimer = self.spawnRate self.spawnAmount = self.spawnAmount - 1 if self.enemyPath ~= "" then local prefab = Prefab:Load(self.enemyPath) if prefab ~= nil then if prefab.script ~= nil then if self.player ~= nil and self.player.script ~= nil then prefab.script.target = self.player.script end prefab:SetPosition(self.entity:GetPosition(true), true) prefab:SetRotation(self.entity:GetRotation(true), true) else prefab:Release() end end end else self.spawnTimer = self.spawnTimer - deltaTime end end It is an enemy spawner that spawns enemies and sets their target as the player. It tries to spawn an enemy and set the script after 5 seconds, so the player script is definitely being loaded first. I'm really not sure why this would happen Quote Link to comment Share on other sites More sharing options...
macklebee Posted February 7, 2016 Share Posted February 7, 2016 Just tried that script and it appears to work just fine for me. No errors and I am being chased by 5 crawlers. Not that it seems to make a difference for me, but you could just set the 'prefab.script.target' to 'self.player' without having to check that the player has a script and it will work as well. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Brutile Posted February 8, 2016 Author Share Posted February 8, 2016 I tried everything to fix this, but nothing worked. I created a test player entity with the same properties as my player and it worked. I was so confused. I ended up re-saving my player prefab to tweak some settings. Still nothing, so I deleted it and put the prefab back exactly how it was. THEN IT WORKED! It turned out to be some bug with Leadwerks, but unfortunately I have no idea how to replicate the bug. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.