Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to compare nil with number? #3

Open
StrifeRider opened this issue Apr 27, 2018 · 1 comment
Open

Attempting to compare nil with number? #3

StrifeRider opened this issue Apr 27, 2018 · 1 comment

Comments

@StrifeRider
Copy link

StrifeRider commented Apr 27, 2018

Hey there,
I've discovered this tool this morning and really like the idea, since I'm searching for a way to show the speed value in call of duty 4 reflex edition next to my game. I found the value with aldelaro's ram watcher and I found 3 corresponding values in Cheat Engine but no matter what I do I always get the following error when trying to run my script: Error:D:/Emu/ram-watch-cheat-engine-0.3/utils.lua:167: attempt to compare nil with number. The value is a float but I don't really know what I'm doing wrong.
Below you can see my tentative code for the script that probably has an obvious error but at least you can point me to it.

``package.loaded.utils = nil
local utils = require 'utils'
local subclass = utils.subclass

package.loaded.dolphin = nil
local dolphin = require 'dolphin'

package.loaded.valuetypes = nil
local valuetypes = require "valuetypes"
local MV = valuetypes.MV
local MemoryValue = valuetypes.MemoryValue
local FloatType = valuetypes.FloatTypeBE

local COD4 = subclass(dolphin.DolphinGame)

COD4.supportedGameVersions = {
na = 'RJAE52',
}

COD4.layoutModuleNames = {'callofduty_layouts'}
COD4.framerate = 30

function COD4:init(options)
dolphin.DolphinGame.init(self, options)
self.startAddress = self:getGameStartAddress()
end

function COD4:VelocityDisplay()
local VelocityAddress = 0x26266350000 + 0x26266A6BBA4
local Velocity = utils.readFloatBE(VelocityAddress)
return "Speed: " .. utils.floatToStr(Velocity)
end

-- Values at static addresses (from the beginning of the game memory).
COD4.StaticValue = subclass(MemoryValue)

function COD4.StaticValue:getAddress()
return self.game.startAddress + self.offset
end

-- Velocity.
COD4.blockValues.vel = MV("Vel", 0x26266A6BBA4, COD4.StaticValue, FloatType)

return COD4``
And my layout.

``package.loaded.utils = nil
local utils = require 'utils'
local subclass = utils.subclass

package.loaded.layouts = nil
local layoutsModule = require 'layouts'
local Layout = layoutsModule.Layout

local layouts = {}

layouts.Velocity = subclass(Layout)
function layouts.Velocity:init()
self:setUpdatesPerSecond(30)
self.window:setSize(400, 300)

self:addLabel{x=6, y=6}
self:addItem(self.game.velocity)
end

layouts.positionRecording = subclass(Layout)
function layouts.positionRecording:init().
self:setBreakpointUpdateMethod()

self:activateAutoPositioningY()

self.window:setSize(400, 160)
self.labelDefaults = {fontSize=12, fontName="Consolas"}

-- Display position.
self:addLabel()
self:addItem(self.game.velocity)

local tabSeparatedPosition = function()
local positionComponents = {
self.game.vel:display{afterDecimal=8, nolabel=true},
}
return table.concat(positionComponents, '\t')
end

self:addFileWriter(
tabSeparatedPosition, 'ram_watch_output.txt')
end

return {
layouts = layouts,
}``
Keep in mind I just went from the sample layouts and scripts and it's litterally just displaying one value in the end, so there's probably a ton of stuff I need to remove and it's probably that that makes it bug somehow. If you could take a quick look and tell me what I'm doing wrong, I'd really appreciate it.

@JoselleAstrid
Copy link
Owner

The error's probably happening when readFloatBE() is called here.

function COD4:VelocityDisplay()
  local VelocityAddress = 0x26266350000 + 0x26266A6BBA4
  local Velocity = utils.readFloatBE(VelocityAddress)
  return "Speed: " .. utils.floatToStr(Velocity)
end

It's reading from the address calculated as 0x26266350000 + 0x26266A6BBA4, which turns out to be 0x4C4CCDBBBA4. Is that what you're trying to do?

You can confirm what's at that address by using Cheat Engine's Memory View window. Click "Memory View", then hit Ctrl+G and enter 0x4C4CCDBBBA4 to go to that address.

One possibility that could lead to the error you're seeing (utils.lua:167: attempt to compare nil with number) is that the address is unreadable for whatever reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants