Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Adding Slow Motion & Getting Error: Attempt to Call Glob

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
hydris
Newbie cheater
Reputation: 0

Joined: 09 Jan 2013
Posts: 19

PostPosted: Sat Jan 19, 2013 6:46 pm    Post subject: Adding Slow Motion & Getting Error: Attempt to Call Glob Reply with quote

Hey,

What I'm trying to do is add 'slow motion' (referred to as Quicksilver) to a game, but it must drain energy (called Devil Trigger, DT in game) while active, and it must be activated like a toggle on a button press when energy is at a certain value.

Previously what I get with the script is, the game isn't being slowed, and after the Lua Engine announces "If statement working", then there's a few seconds of nothing happening, then it announces "If DT is 0,0 check made with some random value in the negatives, then "QS2 called", while no values in game were changed at all.
The values are being read correctly, and parts of this have worked before especially the ones that are having problems now.

Now when I relaunched the game & CE I get (changes to the script is just updated addresses):

Error:[string "--Quicksilver Style for Devil May Cry 4 DX9..."]:22: attempt to call global 'Quicksilver' (a nil value)
I don't understand what's going on for me to get this error all of a sudden.

I'm also not sure on how to express pointers, I'm just updating the address pointed to. The first two lines are an attempt and the output is "testpointer is [blank]"
The game's process name is DevilMayCry4_DX9.exe
The pointer is 00e558d0 with an offset of 34

Here's what I have now; sorry if it's a bit long.

Code:

testpointer = '["DevilMayCry4_DX9.exe"+00E558D0]+34'
print ("testpointer is", readFloat(testpointer))

Quicksilver ()
---------Write Function Here--------------
---------"Game" Function--------------
function Quicksilver () --Quicksilver Check and Enabler
         print ("Quicksilver function called");
         DTdrainTimer = createTimer(window, true); --"Devil Trigger Drain"
          timer_setInterval(DTdrainTimer, 100); --ticks per 100 milliseconds, quantity statement @ line 47

       --'[[[["DevilMayCry4_DX9.exe"+00A552CC]+1f24]+9c]+2e4]+164';--Devil Trigger pointer (entire)

       local DTad = '0x19262AA4'; --Devil Trigger Address; will change per reload
         --local DTad = '[[[["DevilMayCry4_DX9.exe"+00A552CC]+1f24]+9c]+2e4]+164';--Devil Trigger pointer
         DT = readFloat(DTad); --Devil Trigger value
         local EmWR  = '0x17AD85A0'; --Enemy Work Rate; to adjust for different executables, just change this
         local SetWR = '0x17AD85A4'; --Set Work Rate

         print ("DT is", readFloat(DTad)) --debugging
         print ("DTad is", DTad)
         print ("EmWr is ", readFloat(EmWR))
         print ("SetWr is", readFloat(SetWR))

         if DT >= 3000.0 then --required to start
            print ("If statement working");
            writeFloat(EmWr, .2); --Enemy Work Rate
            writeFloat(SetWr, .1);   --Set Work Rate
            timer_onTimer(DTdrainTimer, DTdrain);
         end; --end if statements
end; --end function Quicksilver

function DTdrain () --Devil Trigger Drain; Timer object is created in Quicksilver ()
    --if DT ~= nil then --lazy if fix
   DT = DT - 100.0; --Quantity drained, interval statement @ line 24
    writeFloat(DTad, DT);
    if DT <= 0.0 then --when DT ticks to or below 0,
      print ("If DT is 0.0 check made", DT)
      writeFloat (DTad, 0.0); --in case DT hits a negative number
      Quicksilver2(); -- Quicksilver state ends
     end; --end of if statements
     --end; --lazy if fix
end ; --end function DTdrain

function Quicksilver2 ()--Intended for disabling
         print ("QS2 called")
         object_destroy(DTdrainTimer) --destroys DT drain timer
         writeFloat(EmWr, 1.0); --restores Work Rates to normal
         writeFloat(SetWr, 1.0);
end; --end function Quicksilver 2
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Jan 20, 2013 7:14 am    Post subject: Reply with quote

Because LUA interpreter goes through line-by-line. Functions must be initialized, before you launch them. Move "Quicksilver()" to the bottom.



Quote:
The pointer is 00e558d0 with an offset of 34


So it would be:
print ("testpointer is", readFloat('[DevilMayCry4_DX9.exe+00E558D0]+34') )
or
print ("testpointer is", readFloat('[00E558D0]+34') )
?

Edit:
Maybe something like this:
Code:
-- pointers and addresses
-- to adjust for different executables, just change this

DTad  = "[[[[DevilMayCry4_DX9.exe+00A552CC]+1f24]+9c]+2e4]+164"  --Devil Trigger pointer
EmWR  = "0x17AD85A0" -- Enemy Work Rate
SetWR = "0x17AD85A4" -- Set Work Rate

drainValue    = 100.0
WorkRate      = 0.1
EnemyWorkRate = 0.2

debugMode = true

function debugMessage(s)
  if debugMode then print(s) end
end

---------Write Function Here--------------
---------"Game" Function--------------
function Quicksilver () --Quicksilver Check and Enabler
  debugMessage ("Quicksilver function called")

  DT = readFloat(DTad) --Devil Trigger value

  debugMessage("DT is "..readFloat(DTad)) --debugging
  debugMessage("EmWr is "..readFloat(EmWR))
  debugMessage("SetWr is "..readFloat(SetWR))

  if DT >= 3000.0 then --required to start
     debugMessage("Quicksilver now works")
     writeFloat(SetWr, WorkRate)
     writeFloat(EmWr , EnemyWorkRate)
     timer_setEnabled(DTdrainTimer,true)
  end
end --end function Quicksilver

function DTdrain() --Devil Trigger Drain Timer object is created in Quicksilver ()
  DT = DT - drainValue
  writeFloat(DTad, (DT>0) and DT or 0.0 )

  if DT <= 0.0 then --check if depleted
    timer_setEnabled(DTdrainTimer,false) -- disable timer
    writeFloat(EmWr, 1.0) --restores Work Rates to normal
    writeFloat(SetWr, 1.0)
    debugMessage("DT is 0.0 now ")
  end

end

--prepare timer object
if DTdrainTimer~=nil then object_destroy(DTdrainTimer);DTdrainTimer=nil;end
DTdrainTimer = createTimer(window, false) --"Devil Trigger Drain"
timer_setInterval(DTdrainTimer, 100) --tick per 100 milliseconds
timer_onTimer(DTdrainTimer, DTdrain)

--launch it
Quicksilver()





_________________
Back to top
View user's profile Send private message MSN Messenger
hydris
Newbie cheater
Reputation: 0

Joined: 09 Jan 2013
Posts: 19

PostPosted: Sun Jan 20, 2013 11:11 am    Post subject: Reply with quote

Thanks for the reply; everything's working (after a few other adjustments) and that code does look nice especially with the debugging function and keeping values organized, but Quicksilver2() existed so the effect can be cancelled on a toggle.

Quote:
writeFloat(DTad, (DT>0) and DT or 0.0 )

And can you explain that part? The help file says writeFloat(address, value), but that's an expression.[/quote]
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Jan 20, 2013 4:20 pm    Post subject: Reply with quote

OK, here
Code:
function QuicksilverDisable() --Intended for disabling
         debugMessage("Quicksilver disabled")
         timer_setEnabled(DTdrainTimer,false)
         writeFloat(EmWr, 1.0); --restores Work Rates to normal
         writeFloat(SetWr, 1.0);
end




Quote:
writeFloat(DTad, (DT>0) and DT or 0.0 )
(...)
And can you explain that part?


"The conjunction operator (and) returns its first argument if this value is false or nil; otherwise, and returns its second argument. The disjunction operator (or) returns its first argument if this value is different from nil and false; otherwise, or returns its second argument. Both and and or use short-cut evaluation, that is, the second operand is evaluated only if necessary"

Two cases:
1) DT is bigger than 0

It will be:
true and DT or 0.0

And this is:
DT or 0.0

And this is:
DT

2) DT is less than or equal to 0

It will be:
false and DT or 0.0

And this is:
false or 0.0

And this is:
0.0


It's similar to c++ condition operator ?:

int A = DT>0 ? DT : 0;

_________________
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites