Jump to content

Keypad script makes some user crash.


lxFirebal69xl
 Share

Recommended Posts

Hey gents, here's a weird one.

 

I have a keypad working in my game but some users experience crashes when they press the "Cancel" or the "Accept" button.

 

I zipped up a quick map with how I have it set up.

 

I ran the level I have in the game through VS and came up with an error that according to Josh has no relevance.

 

I am using Genebris Damage Numbers to create the numbers of the keypad.

http://steamcommunity.com/sharedfiles/filedetails/?id=404088984&searchtext=damage

 

Here's the test map:

https://drive.google.com/file/d/0B8hS3jGOv-XEYjBzN25MWnFaOWs/view?usp=sharing

 

 

Keypad code:

Script.player = nil
Script.GotPlayer = false
Script.CodeLen = 4 --int "Code Len"
Script.Code = 1234 --int "Code 123"
Script.CurrentCode = 0
Script.CurrentDigit = 1
Script.Camera = nil

Script.CameraSmoothing = 10
Script.PosCameraSmoothing = 10 --int "Camera smoothing"
Script.CameraTarget = nil
Script.CameraStart = Vec3(0,0,0)

Script.RotCameraTarget = Vec3(5,90,0)
Script.RotCameraStart = Vec3(0,0,0)
Script.Enabled = true --bool "Start enabled?"

Script.Size = 0.1
function Script:Start()
   self.NumPrefabs = {}

   local mepos = Vec3(-1,0,0)
   --mepos = mepos + Vec3(0,0,0)
   local tarpos = Transform:Point(mepos, self.entity, nil)
   self.CameraTarget = tarpos
   --local box = Model:Box(0.25, 0.25, 0.25)
   -- box:SetPosition(tarpos, true)
   local merot = self.entity:GetRotation() + Vec3(0,90,0)
   local tarrot = Transform:Rotation(merot, self.entity, nil)
--    tarrot = tarrot + Vec3(0,90,0)
   self.RotCameraTarget = merot

end

function Script:RemoveNums()
   for i = 1, #self.NumPrefabs do
       self.NumPrefabs[i]:Release()
   end
end

function Script:MakeNums(num)
   for i = 1, #self.NumPrefabs do
       self.NumPrefabs[i]:Release()
   end
   local Ccode = tostring(num)
   local amount = string.len(Ccode)
       for i=1, string.len(Ccode) do
       local entity = Prefab:Load("Damage numbers/prefabs/"..string.sub(Ccode,i,i)..".pfb")
       entity=tolua.cast(entity, "Sprite")
       entity:SetParent(self.entity)
       entity:SetSize(self.Size, self.Size)
       entity:SetPosition(0,0.5,self.Size*amount/2-self.Size/2-self.Size*(i-1))
       entity:SetRotation(0,-90,0)
       --entity:SetColor(color)
       self.NumPrefabs[i] = entity
   end
end



function Script:Use(player)
   if self.Enabled == true then
       self.player = player.entity
       self.GotPlayer = true
       self.CameraStart = player.camera:GetPosition(true)
       self.player.script.Locked = true
       Window:GetCurrent():ShowMouse()
       Window:GetCurrent():SetMousePosition(0,0,0)
       self.RotCameraStart = player.camera:GetRotation(true)

   else
       --What happens if its not enabled and the player uses it? Type code here!
   end
end


function Script:UpdateWorld()

   if self.GotPlayer == true and self.player ~= nil then
       local window = Window:GetCurrent()
       if window:KeyHit(Key.E) or self.Enabled == false then
           self.GotPlayer = false
           self.player.script.Locked = false
           self.player= nil
           window:HideMouse()
           self:RemoveNums()
           return
       end
       local newpos = self.player.script.camera:GetPosition(true)
       newpos.x = Math:Curve(self.CameraTarget.x, newpos.x, self.PosCameraSmoothing)
       newpos.y = Math:Curve(self.CameraTarget.y, newpos.y, self.PosCameraSmoothing)
       newpos.z = Math:Curve(self.CameraTarget.z, newpos.z, self.PosCameraSmoothing)
       self.player.script.camera:SetPosition(newpos,true)
       local newrot = self.player.script.camera:GetRotation(true)
       --newrot = Transform:Rotation(newrot, self.player.camera, self.entity)
       newrot.x = Math:Curve(self.RotCameraTarget.x, newrot.x, self.CameraSmoothing)
       newrot.y = Math:Curve(self.RotCameraTarget.y, newrot.y, self.CameraSmoothing)
       newrot.z = Math:Curve(self.RotCameraTarget.z, newrot.z, self.CameraSmoothing)
       --newrot = Transform:Rotation(newrot, self.entity, nil)
       self.player.script.camera:SetRotation(newrot, true)
       if window:MouseHit(1) then
           local p = window:GetMousePosition()
           p.z = 1 --distance in front of the camera to project to
           p = self.player.script.camera:UnProject(p)
           local pickInfo = PickInfo()


           if self.entity.world:Pick(self.player.script.camera:GetPosition(true), p, pickInfo, 0, true, Collision.Prop) then
                   --System:Print(1)
                   if pickInfo.entity.script ~= nil then
                   local m = pickInfo.entity.script.Key
               --    System:Print(m)
                   --System:Print(1)
                   if m == "0"or m == "1" or m == "2" or m == "3" or m == "4" or m == "5" or m=="6" or m=="7" or m=="8" or m=="9" then
                   if self.CurrentDigit <= self.CodeLen then

                       local l = tonumber(m)
                       self.CurrentCode = self.CurrentCode + (l*(10^(self.CodeLen - self.CurrentDigit)))
                       self.CurrentDigit = self.CurrentDigit + 1
                       System:Print(self.CurrentCode)
                       self.component:CallOutputs("Button Push")


                   end
                   elseif m =="use" then
                       if self.CurrentCode == self.Code then
                               System:Print("correct")
                               self.component:CallOutputs("Correct")
                               self.player.script.Locked = false
                               self.player = nil
                               self.GotPlayer = false
                               self:Cancel()
                           else
                               System:Print("incorrect")
                               self.component:CallOutputs("Incorrect")
                               self:Cancel()
                           end
                   elseif m == "cancel" then
                       self:Cancel()

                   end
               --[[if type(pickInfo.entity.script.Key) == "userdata" then
                   System:Print("here")
                   local m = pickInfo.entity.script.Key
                   System:Print(m)
               --local par = pickInfo.entity:GetParent()
               --local d = par:GetKeyValue("name", "error")
               end--]]
               self:MakeNums(self.CurrentCode)
               end
           end
       end
   end
end

function Script:Cancel() --in
   self.CurrentCode = 0
   self.CurrentDigit = 1
   self.component:CallOutputs("Cancel")
end

function Script:UpdatePhysics()
   if self.GotPlayer == true then
       self.player:Stop()
   end
end

function Script:Enable() --in
   self.Enabled = true
   self.component:CallOutputs("Enable")
end

function Script:Disable() --in
   self.Enabled = false
   self.component:CallOutputs("Disable")
end

function Script:Toggle() --in
   self.Enabled = not self.Enabled
   self.component:CallOutputs("Toggle")
end

Link to comment
Share on other sites

Update #1-

 

Here are the specs of a user that used the keypad without problem:

Rig Intel 5960X, 32 gig mem, Titan X (Maxwell), Windows 10. 1920x1080

 

And the specs of someone who can't use the keypad:

AMD A6-3600 APU with Radeon™ HD Graphics, 8GB RAM, GeForce GTX 750 Ti, Windows 7. 1920x1080

 

My first instinct is to call it an AMD problem because we all know leadwerks has had plenty of those. But the problem is that it outright crashes the game when the user goes through this function:

 

function Script:Cancel() --in
    self.CurrentCode = 0
    self.CurrentDigit = 1
    self.component:CallOutputs("Cancel")
end

Link to comment
Share on other sites

After resetting the code to 0 then clicking another button, it tries to release 4 prefabs instead of 1 and crashes trying to release #2 prefab. See if this fixes it in MakeNums:

 

After this line

local Ccode = tostring(num)

add

if num == 0 then Ccode = "0000" end

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...