Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Game programming

checking to see if a variable has changed

All about the StoneScript

checking to see if a variable has changed

Postby Osbor » 08 Feb 2012, 22:49

sorry to be asking so many questions, but the documentation for shiva is still very sparse, and the wiki quite empty.

is there any way to do an efficient check to see if an object or a variable or whatever has updated? something with signals would be great. at the moment i have a system which checks the hour of the day every frame, when it only needs to know the hour when the hour actually changes (one frame every hour is a lot less overhead than 30 a second)
Osbor
Junior Boarder
Junior Boarder
 
Posts: 39

Re: checking to see if a variable has changed

Postby neilb » 09 Feb 2012, 12:35

There's nothing that does it automatically, but you could use a HUD timer to send a message to your AI to do the hour check once every 30 seconds or however long you want to make the interval.
neilb
Platinum Boarder
Platinum Boarder
 
Posts: 463
Location: Adelaide, South Australia

Re: checking to see if a variable has changed

Postby NiCoX » 09 Feb 2012, 13:57

Yes, or using something like:

Code: Select all
function MyAI.onCheckChanges ( )
   
    -- Actual job
    --
    if ( ... )
    then
        ...
    end

    -- re-check 30sec later
    --
    this.postEvent ( 30, "onCheckChanges" )
end
User avatar
NiCoX
Platinum Boarder
Platinum Boarder
 
Posts: 5642
Location: France

Re: checking to see if a variable has changed

Postby Osbor » 09 Feb 2012, 23:18

NiCoX wrote:Yes, or using something like:

Code: Select all
function MyAI.onCheckChanges ( )
   
    -- Actual job
    --
    if ( ... )
    then
        ...
    end

    -- re-check 30sec later
    --
    this.postEvent ( 30, "onCheckChanges" )
end


oh man, i totally forgot about postEvent! that would work perfectly, since event sends are very little overhead. i could even set the actual clock function to only update the hour every, well, hour (and on initialization of course)
Osbor
Junior Boarder
Junior Boarder
 
Posts: 39


Return to Game programming