Jump to content
  • 0

Return statement does not return desired variable


Platonic

Question

Posted

Script must call function rangeList and return the table that has the variable "range".

Instead the script returns some other value which is not related to the table "range". It takes the variable of valStart instead. Dunno why.

local rangeLoop = 1
function rangeList()
  local range = gg.getRangesList("anon:linker_alloc")
  local valStart = range[rangeLoop].start + origOffsets.RangeStart
  local valEnd = range[rangeLoop]["end"]
  local loop = valEnd - valStart
  return valStart, valEnd, loop, range
end

origOffsets = offsetsISA(offsets)
sizeRange = rangeList(range)
for i = 1, #sizeRange do
  rangeLoop = i
  addStrToExe()
end

 

 

1 answer to this question

Recommended Posts

Posted
27 minutes ago, Platonic said:

Script must call function rangeList and return the table that has the variable "range".

Instead the script returns some other value which is not related to the table "range". It takes the variable of valStart instead. Dunno why.

local rangeLoop = 1
function rangeList()
  local range = gg.getRangesList("anon:linker_alloc")
  local valStart = range[rangeLoop].start + origOffsets.RangeStart
  local valEnd = range[rangeLoop]["end"]
  local loop = valEnd - valStart
  return valStart, valEnd, loop, range -- 1st variable will get valStart , 2ed will get valEnd , 3ed get loop and last get range
end

origOffsets = offsetsISA(offsets)
sizeRange = rangeList(range) -- this will get valStart
for i = 1, #sizeRange do
  rangeLoop = i
  addStrToExe()
end

var1,var2,var3,var4 = rangeList(range)
--[[
var1 = valStart
var2 = valEnd
var3 = loop
var = range
]]
local rangeLoop = 1
function rangeList()
  local range = gg.getRangesList("anon:linker_alloc")
  local valStart = range[rangeLoop].start + origOffsets.RangeStart
  local valEnd = range[rangeLoop]["end"]
  local loop = valEnd - valStart
  return range ,valStart, valEnd, loop -- put range as 1st arg to return
end

origOffsets = offsetsISA(offsets)
sizeRange = rangeList(range) -- sizeRange now will get range
for i = 1, #sizeRange do
  rangeLoop = i
  addStrToExe()
end

local rangeLoop = 1
function rangeList()
  local range = gg.getRangesList("anon:linker_alloc")
  local valStart = range[rangeLoop].start + origOffsets.RangeStart
  local valEnd = range[rangeLoop]["end"]
  local size = valEnd - valStart -- I rename the loop here
  return size , valStart, valEnd, range -- 1st variable assign to this function should recive the size
end

origOffsets = offsetsISA(offsets)
sizeRange = rangeList(range) -- this will get the size
for i = 1, #sizeRange do
  rangeLoop = i
  addStrToExe()
end

 

 

rangeList func is wrong also , 
 

local rangeLoop = 1
function rangeList() -- rangeList recive 0 arg in the declaration
  local range = gg.getRangesList("anon:linker_alloc")
  local valStart = range[rangeLoop].start + origOffsets.RangeStart
  local valEnd = range[rangeLoop]["end"]
  local loop = valEnd - valStart
  return valStart, valEnd, loop, range
end

origOffsets = offsetsISA(offsets)
sizeRange = rangeList(range) -- you passed arg range to rangeList
for i = 1, #sizeRange do
  rangeLoop = i
  addStrToExe()
end
---------------------------------------------------------------Final code should be like this--------------------------
local rangeLoop = 1
function rangeList(range) -- you add arg to rangeList
	if (type(range) ~= 'string') then error(string.format('Wrong arg :%s'range)) end -- error handdler
  local range = gg.getRangesList(range) <-- this line should be like this
  local valStart = range[rangeLoop].start + origOffsets.RangeStart
  local valEnd = range[rangeLoop]["end"]
  local size = valEnd - valStart -- instead of loop
  return size , valStart, valEnd, range -- size should be 1st arg to return
end

origOffsets = offsetsISA(offsets)
sizeRange = rangeList("anon:linker_alloc") -- you pass the name of the range as arg and it should recive the size as 1s arg
for i = 1, #sizeRange do
  rangeLoop = i
  addStrToExe()
end

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.