Jump to content

World Render Method (c++)


Jorns2
 Share

Recommended Posts

Hi, i started programming my game with c++. When i tried to load context,world,window everything is ok. When i call world->Update i give error: attempt to index world a nil value or something like this.

. In definition is virtual void Render();//lua. If i understand this good world->Render method is executed only in .lua script? Why ?

This is caused when i Load map in c++..

 

Thanks for answers.

Link to comment
Share on other sites

9 hours ago, Jorns2 said:

In definition is virtual void Render();//lua. If i understand this good world->Render method is executed only in .lua script? Why ?

No, the comment "//lua" only means that this function is available in lua, as well, but that does not mean, that it is only executed in lua.

As for your other problem, it seems like you might not be setting the variable "world" before calling the Update-function or you are probably setting a function-local variable in the Start-function and then accessing a global variable in the update function or something like that. It's hard to say without seeing your code.

Link to comment
Share on other sites

I have used a example script from documentation

#include "Leadwerks.h"

using namespace Leadwerks;
Model* model = NULL;
int main(int argc, const char *argv[])
{
    Leadwerks::Window* window = Leadwerks::Window::Create();
    Context* context = Context::Create(window);
    World* world = World::Create();
    Camera* camera = Camera::Create();
    camera->Move(0,0,-3);
    Light* light = DirectionalLight::Create();
    light->SetRotation(35,35,0);
        
    model = Model::Box();
    model->SetColor(0.0,0.0,1.0);

    while (true)
    {
        if (window->Closed() || window->KeyDown(Key::Escape)) return false;
    
        model->Turn(0,Leadwerks::Time::GetSpeed(),0);
        
        Leadwerks::Time::Update();
        world->Update();
        world->Render();
        context->Sync(false);

    }
    return 0;
}

and then:

 

image.thumb.png.2a9e167c54a66c83d27f5c32e0dee777.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...