-
Posts
141 -
Joined
-
Last visited
Content Type
Blogs
Forums
Store
Gallery
Videos
Posts posted by GorzenDev
-
-
using a global variable like that will result in undefined behaviour.
make sure you process each event before the while loop ends.you would be better off to store a pointer to mudaLocalGui as global variable,
add a process function to your script,
and call it from your event loop. (remove the pointer after closing the menu )
personally i would use some kind of guimanager script, instead of processing your events in Main.lua.
example of a gui manager:import("Scripts/MainMenu.lua") import("Scripts/GameMap.lua") import("Scripts/GameGUI.lua") function BuildGUIManager(context) local Manager = {} -- Manager.gamemenu = BuildMenu(context, Manager) Manager.gamemenu:Show() -- Manager.gamemap = BuildGameMap(context) Manager.gamemap:Hide() -- Manager.gameui = BuildGameGUI(context, Manager) Manager.gameui:Hide() ------------------------------------------------ function Manager:MenuHidden() return self.gamemenu:Hidden() end function Manager:ShowGameMenu() self.gamemenu:Show() self.gameui:Hide() end function Manager:HideGameMenu() self.gameui:Show() self.gamemenu:Hide() end -- function Manager:Update() -- if self.gamemenu:Hidden() == false then self.gamemenu:Update() end if self.gamemap:Hidden() == false then self.gamemap:Update() end if self.gameui:Hidden() == false then self.gameui:Update() end -- while EventQueue:Peek() do local event = EventQueue:Wait() local event_processed = false --process menu if self.gamemenu:Hidden() == false then if self.gamemenu:ProcessEvent(event) == false then --exit game return false end end --process map if self.gamemap:Hidden() == false then event_processed = self.gamemap:ProcessEvent(event) end --process ui if event_processed == false and self.gameui:Hidden() == false then self.gameui:ProcessEvent(event) end end -- return true end -- -- return Manager end
-
i used to do something like this...
this will only add keyinfo to the Keys table when a key is actually used.
to make it work you would need to add a call to PreUpdate() in your main loop.
to check a key's state you would call eg: IsKeyUp(Key.W) or IsKeyDown(Key.W).function SetKeyboardInfoPack() local pack = { Keys = {}, -- FlushKeyInfo = function (self, resetHit, key) if key ~= nil then local nHit = 0 if self.Keys[key] ~= nil and resetHit == false then nHit = self.Keys[key].hit end self.Keys[key] = {down = false, up = false, hit = nHit} else local nHit = 0 for key,value in pairs(self.Keys) do if resetHit == false then nHit = self.Keys[key].hit end self.Keys[key] = {down = false, up = false, hit = nHit} end end end, -- PreUpdate = function (self) self:RefreshKeyStates() end, -- IsKeyDown = function (self, key) --create a key record if not already exists and check the keystate if self.Keys[key] == nil then self.Keys[key] = {down = false, up = false, hit = 0} self:RefreshKey(key) end --return keystate return self.Keys[key].down end, -- IsKeyUp = function (self, key) --create a key record if not already exists and check the keystate if self.Keys[key] == nil then self.Keys[key] = {down = false, up = false, hit = 0} self:RefreshKey(key) end --return keystate return self.Keys[key].up end, Keyhits = function (self, key) --create a key record if not already exists and check the keystate if self.Keys[key] == nil then self.Keys[key] = {down = false, up = false, hit = 0} self:RefreshKey(key) end --return keystate return self.Keys[key].hit end, -- RefreshKeyStates = function (self) for key,value in pairs(self.Keys) do self:RefreshKey(key) end end, RefreshKey = function (self, key) if key ~= nil then if self.Keys[key] ~= nil then if window:KeyDown(key) then self.Keys[key].down = true self.Keys[key].up = false elseif self.Keys[key].down == true then --last state down self.Keys[key].down = false self.Keys[key].up = true self.Keys[key].hit = self.Keys[key].hit + 1 elseif self.Keys[key].up == true then --last state up self.Keys[key].down = false self.Keys[key].up = false end end end end } -- return pack end
-
they all definitly work no doubt about it.
are you certain that the variable you try to read/write actually exists in the widget script??
i assume you are looking for.widget:SetFloat("radius", 2); widget:GetFloat("radius");
REMEMBER !!!
call widget:Redraw() when you change a variable's value.
often you would think "hey this does not work" while it usually does work but is not updated yet ? -
The BaseActor class i use to derive actors from.
Use it just like you would use a entity script.
Attach actor to a entity.baseActor = new BaseActor(); entity->SetActor(baseActor);
BaseActor.h#include "Leadwerks.h" using namespace Leadwerks; const enum class ActorType : char { Base, Player, NPC}; class BaseActor : public Actor { //Built-in extendable functions // //virtual void EndAnimation(const int sequence); virtual void Sleep(); //virtual void Wake(); virtual void Attach(); //virtual void Detach(); //virtual void Collision(Entity* entity, const Vec3& position, const Vec3& normal, float speed); virtual void UpdateWorld(); virtual void UpdatePhysics(); //virtual void UpdateMatrix(); virtual void PostRender(Context* context); //virtual void Draw(); //virtual void DrawEach(Camera* camera); //virtual void ReceiveSignal(const std::string& inputname, Entity* sender); public: ActorType actorType = ActorType::Base; BaseActor(); virtual ~BaseActor(); };
BaseActor.cpp#include "BaseActor.h" BaseActor::BaseActor() { } BaseActor::~BaseActor() { } void BaseActor::Attach() { // //System::Print("BaseActor Attached."); } void BaseActor::Sleep() { // //System::Print("BaseActor Sleep."); } void BaseActor::UpdateWorld() { //System::Print("BaseActor UpdateWorld."); } void BaseActor::UpdatePhysics() { //System::Print("BaseActor UpdatePhysics."); } void BaseActor::PostRender(Context* context) { // }
- 1
-
7 hours ago, tipforeveryone said:
Anyone remind me a function which returns animation ID of a model by input Animation name?
something like this: local animID = model:GetAnimationID("running_loop")
I think this function is not in document but it exists
I remember that Josh told me about it once
Definition Entity.h
virtual int FindAnimationSequence(const std::string& sequence);//luaEntity::FindAnimationSequence("sequencename")
-
whenevver i loose my motivation i actually force myself to do at least 4 hours of coding each week.
which in turn motivates me because i progress. (even if its just small progress)
this brings me in a vicious circle that keeps me going.
- 1
-
You could always edit the "common" template and remove the files you dont want to be copied.
Dont forget to backup before editing.
-
create your own "BlankProject" template its very easy and saves you a lot of time.
i remember i made a post somewhere on how to do it.- 1
-
you could create your own pre-post processor function in your main.lua, and have that execute when you want.
- 1
-
i'm thinking this is due to NVIDIA trying to force/overwrite game settings when you manually set them.
try using default nvidia settings and let leadwerks do its thing...
-
It all started with a game called 'legend of mir', some guy got a hold of the sourcecodes and decided to release those. (source codes where in delphi 7)
with my knowledge of the game i started to search through the project to find references of spells that i knew the mechanics of
and slowly i started to understand the basics of how such spells worked.
The obvious next step for me whas to add my own custom spell to the game, compile/run and jump for joy.
how excited i whas that i just pulled that off
some 16 years later i still am just as excited and i learned a few extra languages.
i do admit i never went to school for this. -
that is one option.
i recommend moving the event loop outside of the menu file though.
then call processevent(event) with a return value on any table that needs to process events.
for example in my current c++ project i actualy have a class called GUIManager which holds the event loop.
which in turn calls other gui classes to update and grab events.
when that call returns true then the event is processed and there is no need to call other classes with that event.
example code(C++) ://Handle GUI events while (EventQueue::Peek()) { Event event = EventQueue::Wait(); // //Update menu UI events if (!gamemenu->Hidden()) { //exit game if (gamemenu->ProcessEvent(event) == false) return false; } //update game UI events if (!gameui->Hidden()) gameui->ProcessEvent(event); }
-
you can create multiple GUI to hold widgets.
but only one event loop can be used. -
self.entity:SetMass(5)
self.enity:GetMass()
- 1
-
i think this will get you the answer you need.
-
almost forgot... checkout AggrorJorns plugin for visual studio code. very helpfull
https://www.leadwerks.com/community/blogs/entry/2145-visual-studio-code-for-leadwerks/ -
your best option would be to use the search function on the forum.
other than that the demo projects that come with leadwerks basicly show all you can do. -
https://www.leadwerks.com/learn?page=Tutorials_Lua-Scripting_Introduction-to-Lua
scroll all the way down.
it is realy not that hard to find resources for Leadwerks to be honest.- 1
-
like spiderpig said only lua is accepted in that box.
But.......
The c++ Actor class is what your looking for.- 2
-
we basicly posted at the same time
you could use different approaches.
either send a widget event whenevver any text is typed into the field by using "Option 1".
or send a widget event whenevver the "ENTER" key is pressed "Option 2". (assume the user is done typing)
or send an widget event whenevver the "TAB" key is pressed "Option 3". (assume the user wants to switch to the next element in case of a form that needs filling)
if a WidgetAction event interferes with other events you could always use WidgetSelect or WidgetMenu events--OPTION 1-- function Script:KeyChar(charcode) local s = self.widget:GetText() local c = String:Chr(charcode) if c=="\b" then --Backspace if String:Length(s)>0 then if self.sellen==0 then if self.caretposition==String:Length(s) then s = String:Left(s,String:Length(s)-1) elseif self.caretposition>0 then s = String:Left(s,self.caretposition-1)..String:Right(s,String:Length(s)-self.caretposition) end self.caretposition = self.caretposition - 1 self.caretposition = math.max(0,self.caretposition) else local c1 = math.min(self.caretposition,self.caretposition+self.sellen) local c2 = math.max(self.caretposition,self.caretposition+self.sellen) s = String:Left(s,c1)..String:Right(s,String:Length(s) - c2) self.caretposition = c1 self.sellen = 0 end self.widget:GetGUI():ResetCursorBlink() self.cursorblinkmode=true self.widget.text = s self.widget:Redraw() end elseif c~="\r" and c~="" then --Insert a new character local c1 = math.min(self.caretposition,self.caretposition+self.sellen) local c2 = math.max(self.caretposition,self.caretposition+self.sellen) s = String:Left(s,c1)..c..String:Right(s,String:Length(s) - c2) self.caretposition = self.caretposition + 1 if self.sellen<0 then self.caretposition = self.caretposition + self.sellen end self.sellen=0 self.widget:GetGUI():ResetCursorBlink() self.cursorblinkmode=true self.widget.text = s self.widget:Redraw() -- --OPTION 1-- --send event with data = 999 EventQueue:Emit(Event.WidgetAction,self.widget,999) end end function Script:KeyUp(keycode) if keycode==Key.Shift then self.shiftpressed=false end -- if keycode==Key.Enter then self.widget:GetGUI():SetFocus(nil) -- --OPTION 2-- --send event with data = 997 EventQueue:Emit(Event.WidgetAction,self.widget,997) elseif keycode==Key.Tab then self.widget:GetGUI():SetFocus(nil) -- --OPTION 3-- --send event with data = 998 EventQueue:Emit(Event.WidgetAction,self.widget,998) end end
-
I'm not at my pc right now but from the top of my head I would say.
Open textfield.lua, scroll all the way down and add a widget event call to the keychar or keydown/up method.
You will find examples of calling an event inside any widget script.
I will add a proper example when I get home.
-
better yet c++ can call functions straight out of the widgetscript.
so create a nice widget script set it to your widget and call functions from c++.
other than that c++ can do exactly the same as lua can when it comes to widgets.
sorry i forgot to add usage for the colorlabel.
use the above colorlabel script like this:--create a custom widget colorlabel = Widget:Create("", 100, 100, 250, 12, gui:GetBase(), "Scripts/GUI/ColorLabel.lua") colorlabel:SetObject("textcolor", Vec4(1.0, 0.0, 0.0, 1.0))
-
to set a label's text color you would need to either edit the default label.lua or create a custom one.
here is code for a colorLabel:--Styles if Style==nil then Style={} end if Style.Label==nil then Style.Label={} end Style.Label.Left=0 Style.Label.Center=16 Style.Label.Right=8 Style.Label.VCenter=32 Script.bordercolor = Vec4(0.2,0.2,0.2,1) Script.textcolor = Vec4(0.7,0.7,0.7,1) --[[ Const LABEL_LEFT=0 Const LABEL_FRAME=1 Const LABEL_SUNKENFRAME=2 Const LABEL_SEPARATOR=3 Const LABEL_RIGHT=8 Const LABEL_CENTER=16 ]] function Script:Draw(x,y,width,height) local gui = self.widget:GetGUI() local pos = self.widget:GetPosition(true) local sz = self.widget:GetSize(true) local scale = gui:GetScale() local text = self.widget:GetText() local indent=4 if self.border==true then gui:SetColor(self.bordercolor.r, self.bordercolor.g, self.bordercolor.b, self.bordercolor.a) gui:DrawRect(pos.x,pos.y,sz.width,sz.height,1) end --gui:SetColor(0.7,0.7,0.7) gui:SetColor(self.textcolor.r,self.textcolor.g,self.textcolor.b,self.textcolor.a) if text~="" then local style=0 if self.align=="Left" then style = Text.Left end if self.align=="Center" then style = Text.Center end if self.align=="Right" then style = Text.Right end if self.valign=="Center" then style = style + Text.VCenter end if self.wordwrap==true then style = style + Text.WordWrap end if self.border==true then gui:DrawText(text,pos.x+scale*indent,pos.y+scale*indent,sz.width-scale*indent*2,sz.height-scale*indent*2,style) else gui:DrawText(text,pos.x,pos.y,sz.width,sz.height,style) end end end function Script:bitand(set, flag) return set % (2*flag) >= flag end
- 2
-
the problem lies with window:HideMouse(), it is being called a couple times inside Menu.lua remove or comment out those lines and you wont have no problems anymore.
I can't add the button with image via c++
in Programming
Posted
if i remember correctly you need the GUI to initialize the image.
example: