PDA

View Full Version : Where is the "onSomething" docs?



speeder
03-23-2010, 04:15 AM
Hello, I noticed that NovaShell logic is mainly based "onEvent" function declarations (similar to Unity, Processing, Flash...)

The thing is: I am not finding the documentation on it, not even to create a better menu that highlights the buttom that I am hovering the mouse over...

I searched everywhere on the site, reference, etc... And I am still not finding it...

Seth
03-26-2010, 02:08 AM
Not sure I understand really, but I'll try..

Functions starting with On* are just a way to show that the engine calls them on an Entity automatically. A list is here (http://www.rtsoft.com/novashell/docs/api/files/EntityBindings-cpp.html#Entity).

If you want a click/mouse movement to call a function, use InputManager::AddBinding (http://www.rtsoft.com/novashell/docs/api/files/InputManager-cpp.html#InputManager.AddBinding).

If you want to schedule your own events, look at this (http://www.rtsoft.com/novashell/docs/api/files/GlobalScriptFunctionBindings-cpp.html#Schedule).

Btw, I actually did do a better menu system with a nice hover effect, you should check out here (http://www.ludumdare.com/compo/2009/02/08/myth-hunter-final/). (inside is a novashell project with source - might be helpful to use as an example)

speeder
03-26-2010, 04:51 AM
Oh, you understood me.

And thank you for the other usefull info...

But the list, is not on the link that you pasted (and I still want that list...) It only mentions the default stuff created when a new script is created.

TSO
06-03-2010, 02:59 PM
I'm lookin at more advanced AI code and found these "On*" functions being used.
I filled them with logmsg's to track what order they fire off and assumed it was based on the 'state' you put the entity in.

Ripped from Top View RPG top_troll.lua:


function OnPostInit()

m_hp = 4;

if this:GetScale().x < 1 then
m_hp = 5; //he's small I guess, give him less HP
end

this:GetBrainManager():Add("StandardBase","");
this:GetBrainManager():SetStateByName("Idle");

end

function OnAttackLoop()

//attack anim is finished playing
this:GetBrainManager():SetStateByName("Idle");
end


function OnIdleLoop()

if (this:GetGoalManager():GetGoalCount() > 0) then
return;
end

if (CanAttack()) then return; end;

if (math.random(2) == 1) then
this:GetBrainManager():SetStateByName("Walk");
end
end

function CanAttack()

if (GetPlayer and this:GetDistanceFromEntityByID(GetPlayer:GetID()) < 50) then

//well, we're close enough to the player, but we better check to see if we're facing
//towards him or not.

//first, let's tell the AI we want to rotate towards him
this:SetVectorFacingTarget(this:GetVectorToEntity( GetPlayer));

//only if we're already looking at him should we swing

local toleranceAngleInRadians = 1.3;
if (this:IsFacingTarget(toleranceAngleInRadians)) then

this:GetBrainManager():SetStateByName("Attack");
return true;
end
end

return false;
end


You said

Functions starting with On* are just a way to show that the engine calls them on an Entity automatically.

So based on the code above would the functions fire in this order?:



function OnPostInit()
function OnAttackLoop()
function OnIdleLoop()
OR


function OnPostInit()
function OnIdleLoop()
function CanAttack()
function OnWalkLoop()