Jump to content

Rick

Members
  • Posts

    7,936
  • Joined

  • Last visited

Everything posted by Rick

  1. Rick

    entity name

    I just copied the light and commented the light specific stuff out. dofile("Scripts/base.lua") -- We need the base class entity function InitDialog(grid) base_InitDialog(grid) --group=grid:AddGroup("Light") --group:AddProperty("Resolution",PROPERTY_CHOICE,"256,512,1024,2048") --group:AddProperty("linearoffset",PROPERTY_FLOAT,"0,1,2","Linear offset") --group:AddProperty("multoffset",PROPERTY_FLOAT,"0,1,2","Multiplicative offset") --group:AddProperty("Range",PROPERTY_FLOAT,"1,100,0") --group:Expand(1) end function Spawn(model) local entity=base_Spawn(model) entity.model=model --entity.light=CreatePointLight(10,model) entity.pivot = CreatePivot() return entity end function GetKey( model, key, value ) local entity=entitytable[model] if entity==nil then return value end if entity.model==nil then return end return base_GetKey(model,key,value) --if entity.light==nil then --return base_GetKey(model,key,value) --else --if key=="linearoffset" then -- return entity.light:GetShadowOffset(0,0)--..","..entity.light:GetShadowOffset(0,1)..","..entity.light:GetShadowOffset(0,2) --elseif key=="multoffset" then -- return entity.light:GetShadowOffset(1,0)--..","..entity.light:GetShadowOffset(1,1)..","..entity.light:GetShadowOffset(1,2) --elseif key=="range" then -- return entity.light:GetRange() --else -- return base_GetKey(model,key,value) --end --end end function SetKey(model, key,value) local entity=entitytable[model] if entity==nil then return 1 end if entity.model==nil then return 1 end base_SetKey(model,key,value) if entity.light==nil then --base_SetKey(model,key,value) else --if key=="resolution" then -- if value=="0" then -- entity.light:SetShadowmapSize(256) -- elseif value=="1" then -- entity.light:SetShadowmapSize(512) -- elseif value=="2" then -- entity.light:SetShadowmapSize(1024) -- elseif value=="3" then -- entity.light:SetShadowmapSize(2048) -- end --elseif key=="range" then -- entity.light:SetRange(value) --elseif key=="shadowresolution" then -- resolution=entity.light:GetShadowmapSize() -- if resolution==256 then -- return 0 -- elseif resolution==512 then -- return 1 -- elseif resolution==1024 then -- return 2 -- elseif resolution==2048 then -- return 3 -- else -- return -1 -- end --elseif key=="multoffset" then -- entity.light:SetShadowOffset(entity.light:GetShadowOffset(0,0),value,0) --elseif key=="linearoffset" then -- entity.light:SetShadowOffset(value,entity.light:GetShadowOffset(1,0),0) --else -- return base_SetKey(model,key,value) --end end return 1 end
  2. Rick

    entity name

    I still have something funky about my custom pivot entity. After the first time I save the scene and close it then reopen no matter where I move it and save the scene again, closing the editor and reopening it the pivot will always go back to where it was originally saved.
  3. Rick

    Single-state Lua

    What is happening there? I assume the editor calls light_directional_CreateClass(). Which defines the other functions in the class table and then returns the class table to the editor, which then can call the functions defined inside light_directional_CreateClass? So I assume the editor will save off the class table per model in the scene so it can call the functions defined in it. It's not the worst just seems the light_directional_CreateClass() function should be more of a class. I'm just used to C++ more than lua, but I get what it's doing. Do we have access to the preprocessor? I might try to make something just for myself and the scripts I create.
  4. Rick

    Single-state Lua

    I just don't think people will be comfortable with those 2 options above. It's not all that straight forward. So just trying to think of other ideas.
  5. Rick

    Single-state Lua

    I agree, fewer lines that I have to type the better. Your example of how to do it however isn't much fewer. I was more thinking of some kind of preprocessor macro stuff to make things look easier. Not sure if lua has that sort of thing.
  6. Rick

    Looping entities

    Oh, good call. CurrentWorld(). How do I get the main world's entities?
  7. Rick

    Single-state Lua

    Is there any way that can be cleaned up somehow? 3 nested functions SetKey() and everything needs to be in a nested function Create() just seems kind of messy. Even if this is how it has to be, there might be a way to hide some of this so it looks more straight forward.
  8. Rick

    Looping entities

    Oh sorry in spawn I make it false. It gets into the function because I see the Print() in the log that Test() does. So I know it's getting into Test().
  9. How does he limit it to be used from the editor only?
  10. OK I'm confused as to what is happening here. I'm trying to create a GetEntityByName(name) function. In it, it will loop CurrentWorld().entities looking for the key name you pass in. So step one I just want to print all entity names. for model in iterate(CurrentWorld().entities) do Print("Searching name.. "..model:GetKey("Name")) end The thing I don't get is if I put this in the Update() method it prints all the entities, BUT if I put this in a function that gets ran just once from inside Update() (it's like an init thing inside Update() where it'll only run the function inside and if statement) in my log all I see is 1 line of "Searching name... ". It's blank. [EDIT] Here is the code in monster truck lua How it's setup below I see Inside test print in the log but no entities looped through in the log. If I uncomment the GetEntityByName("test") in the Update() method it does loop through all entities. So what's the difference? function Test() Print("Inside test") GetEntityByName("Rick") end function Update(world) local model local entity for model,entity in pairs(entitytable) do entity:UpdateTires() end if(init == false) then if(GetGlobalNumber("game") == 1) then --Print("Running MyScript") init = true --RunScript(MyScript) Test() end end --for m in iterate(CurrentWorld().entities) do -- Print("Searching name.. "..m:GetKey("Name")) --end --GetEntityByName("test") UpdateCR() end
  11. Rick

    entity name

    worked now. not sure what happened.
  12. Rick

    entity name

    So I copied the light entity to make a pivot entity. The name property doesn't seem to stick. I set it, click apply, close the properties window, and when I go back in the name is blank again. What needs to happen for these properties to hold their value?
  13. Perfect, thanks. Couldn't find it.
  14. That doesn't seem to work. I have this code in the Update of vehicle_monstertruck.lua and that is in my scene. When I open up the scene I have saved with this code in it I get "attempt to call global 'iterate' (a nil value)" error. Did you make the iterate function in lua? If so what lua file?
  15. So how would I get the name property of the entities while looping through them? I'm trying the below with no luck. I also tried a few variations of this but still no luck for entity in iterate(CurrentWorld().entities) do Print("Entity name = "..entity.model:GetKey("name")) end
  16. Because it makes the code "cleaner". I think he should have named it something else besides Update() because it can look confusing. In his other scripts he does stuff like UpdateTires() which makes more sense. In some scripts you might want to do 4 different things and putting all that inside Update() will mess that method up.
  17. There is a need to run code every cycle so this is just how Josh decided to do it.
  18. Rick

    Single-state Lua

    That looks to be about the only new thing. You could probably encapsulate that with a function call. Maybe like: InitEntity("light_directional") You should be able to do: function InitEntity(ent) _G[ent.."_InitDialog"] = base_InitDialog ... end
  19. Rick

    C++ events

    np. I'd love to see what you do with it.
  20. Rick

    C++ events

    Here is a small example of how to use it. This assumes you took the above code and put it in a file named Event.h Widget.h #pragma once #include "Event.h" #include <string> using namespace std; class Widget { private: void Widget_onClick(Widget* w, string p); public: Widget(void); ~Widget(void); public: Event2<Widget*, string> onClick; }; Widget.cpp #include "Widget.h" Widget::Widget(void) { onClick.Bind(this, &Widget::Widget_onClick); } Widget::~Widget(void) { } void Widget::Widget_onClick(Widget *w, std::string p) { } mian.cpp #include "Widget.h" int main() { Widget w; w.onClick.Raise(&w, "hello"); // this will end up calling Widget::Widget_onClick which is a private function of Widget return 0; }
  21. Rick

    C++ events

    Here it is in all it's glory. It's very much like how C# handles events. If you are familiar with C# you know that all events take 2 parameters. If you aren't familiar with templates your head might explode following the code below. You will note that below is for an event that takes 2 parameters to the functions that you link to it and returns a void. Because this uses templates those parameter types are defined by you like so Event2<int, string> myEvent; You can just put this in a header file, and include that header file wherever you want to use this and you're good to go. #include <list> using namespace std; template<class P, class Q> class TFunctor2 { public: virtual void Call(P var1, Q var2)=0; }; template <class TClass, class param1, class param2> class TSpecificFunctor2 : public TFunctor2<param1, param2> { private: void (TClass::*fpt)(param1, param2); TClass* pt2Object; public: TSpecificFunctor2(TClass* _pt2Object, void(TClass::*_fpt)(param1, param2)) { pt2Object = _pt2Object; fpt=_fpt; } virtual void Call(param1 var1, param2 var2) { (*pt2Object.*fpt)(var1, var2); } }; template<class T1, class T2> class Event2 { public: list<TFunctor2<T1, T2>* > mCaller; template<class Target> Event2(Target* t, void (Target::*fnPtr)(T1, T2)) { mCaller.push_back(new TSpecificFunctor2<Target, T1, T2>(t,fnPtr)); } Event2(){} template<class Target> void Bind(Target* t, void (Target::*fnPtr)(T1, T2)) { mCaller.push_back(new TSpecificFunctor2<Target, T1, T2>(t,fnPtr)); } void Raise(T1 V1, T2 V2) { list<TFunctor2<T1, T2>*>::reverse_iterator iter; for (iter = mCaller.rbegin(); iter!= mCaller.rend(); iter++) { (*iter)->Call(V1, V2); } } void Clear() { mCaller.clear(); } }; I didn't create this code so I can't take credit for it. I learned it from another game programming library, but honestly I have never seen a better C++ event system than what this gives you. This is as close to how .NET handles events that you can get in C++. It's easy to use. I would highly recommend studying the code and actually understand how it's working because it's pretty powerful, but for the first few months I just used it and didn't care how it worked If you want to create event functions that have different signatures then you would copy the above code, and do some renaming and re-templating. For example if you wanted a function that took 3 variables you would change the function names to have a 3 at the end, and then add another template class type to the classes. I gave you 2 parameter signature because that's how .NET handles events. It passes in the calling object and the parameter structure.
  22. I got all 3 of these functions working. I'm working on an script to show how these 3 will work. DoSound(cr, 'abstract::hello.wav') DoMoveTo(cr, fw.main.camera, GetEntityByName("pivot01"), .05, 1) -- moving the camera to the pivot named pivot01 at a rate of 0.5 and it'll stop when it's at a distance of 1. This move function doesn't use physics. Another function will use physics for movement.
  23. It works for me. You have to move your mouse up and down but I noticed it's hard to see the change in elevation if you don't have a texture. Even with a texture it can be hard to see. Not sure if shadows aren't on by default?
  24. Same here. I can't follow how that is working at all. Never seen that syntax. It's almost like it's a with statement with all the .Function()
×
×
  • Create New...