#StackBounty: #c++ #lua #entity-component How to store Lua script's inner state?

Bounty: 50

Situation:

  • I am working on an Entity-Component system, and I am using LuaBridge as a Lua binder.

  • There is only one Lua State.

  • Currently when I update the game objects, I just check whether it has a script defined or not. If there is, I call luaL_dostring() on it, and I call its update() function.

  • I have a script, where I declare a global variable in its start() (it is called when the script runs for the first time), and increment it at every update() then print it out

Question:

  • I would like to achieve separated inner state saving for my scripts.
    • For example If I add the same script to two different game objects, currently the printed out numbers will be 1,2,3,4,5,6 instead of 1,1,2,2,3,3, etc.
    • This is because they use the same Lua State (correct me if I am wrong)

    • But as I heard it’s not a good practice to have a lua state for every script because If I just have 5 scripts, and I add these to 3 different game objects, there would be already 15 lua states.

How should I achieve my goal?


Get this bounty!!!

#StackBounty: #c++ #lua #entity-component How to store Lua script's inner state?

Bounty: 50

Situation:

  • I am working on an Entity-Component system, and I am using LuaBridge as a Lua binder.

  • There is only one Lua State.

  • Currently when I update the game objects, I just check whether it has a script defined or not. If there is, I call luaL_dostring() on it, and I call its update() function.

  • I have a script, where I declare a global variable in its start() (it is called when the script runs for the first time), and increment it at every update() then print it out

Question:

  • I would like to achieve separated inner state saving for my scripts.
    • For example If I add the same script to two different game objects, currently the printed out numbers will be 1,2,3,4,5,6 instead of 1,1,2,2,3,3, etc.
    • This is because they use the same Lua State (correct me if I am wrong)

    • But as I heard it’s not a good practice to have a lua state for every script because If I just have 5 scripts, and I add these to 3 different game objects, there would be already 15 lua states.

How should I achieve my goal?


Get this bounty!!!

#StackBounty: #c++ #lua #entity-component How to store Lua script's inner state?

Bounty: 50

Situation:

  • I am working on an Entity-Component system, and I am using LuaBridge as a Lua binder.

  • There is only one Lua State.

  • Currently when I update the game objects, I just check whether it has a script defined or not. If there is, I call luaL_dostring() on it, and I call its update() function.

  • I have a script, where I declare a global variable in its start() (it is called when the script runs for the first time), and increment it at every update() then print it out

Question:

  • I would like to achieve separated inner state saving for my scripts.
    • For example If I add the same script to two different game objects, currently the printed out numbers will be 1,2,3,4,5,6 instead of 1,1,2,2,3,3, etc.
    • This is because they use the same Lua State (correct me if I am wrong)

    • But as I heard it’s not a good practice to have a lua state for every script because If I just have 5 scripts, and I add these to 3 different game objects, there would be already 15 lua states.

How should I achieve my goal?


Get this bounty!!!

#StackBounty: #c++ #lua #entity-component How to store Lua script's inner state?

Bounty: 50

Situation:

  • I am working on an Entity-Component system, and I am using LuaBridge as a Lua binder.

  • There is only one Lua State.

  • Currently when I update the game objects, I just check whether it has a script defined or not. If there is, I call luaL_dostring() on it, and I call its update() function.

  • I have a script, where I declare a global variable in its start() (it is called when the script runs for the first time), and increment it at every update() then print it out

Question:

  • I would like to achieve separated inner state saving for my scripts.
    • For example If I add the same script to two different game objects, currently the printed out numbers will be 1,2,3,4,5,6 instead of 1,1,2,2,3,3, etc.
    • This is because they use the same Lua State (correct me if I am wrong)

    • But as I heard it’s not a good practice to have a lua state for every script because If I just have 5 scripts, and I add these to 3 different game objects, there would be already 15 lua states.

How should I achieve my goal?


Get this bounty!!!

#StackBounty: #c++ #lua #entity-component How to store Lua script's inner state?

Bounty: 50

Situation:

  • I am working on an Entity-Component system, and I am using LuaBridge as a Lua binder.

  • There is only one Lua State.

  • Currently when I update the game objects, I just check whether it has a script defined or not. If there is, I call luaL_dostring() on it, and I call its update() function.

  • I have a script, where I declare a global variable in its start() (it is called when the script runs for the first time), and increment it at every update() then print it out

Question:

  • I would like to achieve separated inner state saving for my scripts.
    • For example If I add the same script to two different game objects, currently the printed out numbers will be 1,2,3,4,5,6 instead of 1,1,2,2,3,3, etc.
    • This is because they use the same Lua State (correct me if I am wrong)

    • But as I heard it’s not a good practice to have a lua state for every script because If I just have 5 scripts, and I add these to 3 different game objects, there would be already 15 lua states.

How should I achieve my goal?


Get this bounty!!!

#StackBounty: #c# #asp.net #angularjs #asp.net-mvc #session-cookies Using HttpCookie for timeout/ url expiration

Bounty: 50

I’m working a web application, which is MVC 5 + Angular JS hybrid. There is no authentication in the web app and an anonymous user can come and ask for price for certain services. To get the price the user needs to answer some questions spread across few pages. Here is the flow of app.

  1. User clicks button to get price

  2. A unique URI the request is generated and user is redirect to the questions page

  3. User answers questions and user submits the answers. The questions are spread across multiple pages navigated through angular routing. The answers are saved back to server on page navigation.

  4. Once, the user submits the answers, the system (server) generate the price and display it to user.

Currently, if the user has bookmarked the URI, he can come back after days and continue from where he left. I want to prevent this behaviour.

What are the different options do I have in MVC? I can think of following:

  1. Using HttpCookie with expiration time
  2. Save the last access time in DB and validate if the user has come within a stipulated time frame?

I would like to avoid HttpSession. I’m inclined towards using HttpCookie since it looks to be the simplest option.

  1. If we go with HttpCookie option, are there any side effect that I need to keep in mind?
  2. Are there any other alternative within MVC I can look for?


Get this bounty!!!

#StackBounty: #c# #.net #linq #c#-4.0 #pivot C# How to pivot multi dimensional data stored as List<List<string>>

Bounty: 100

I am receiving data from a data source which I need to pivot before I can send the information to UI for display. I am new to concept of pivoting & I am not sure how to go about it.

There are two parts to the problem:

  1. forming the header
  2. Pivoting the data to match the header

Things to keep in mind:

  1. I have certain columns which I do not want to pivot. I call them static columns.

  2. I need to pivot certain columns to form multi level header info. I call them dynamic columns

  3. Some columns needs to be pivoted which contains actual values. I called them value columns.

  4. There is NO limit on number of dynamic, static and value columns one can have.

  5. It is assumed that, when data comes, we will first have data for static columns then dynamic columns & then for value columns.

    See the attached image for more information.

enter image description here

Dummy data:

class Program
    {
        static void Main(string[] args)
        {
            var _staticColumnCount = 2; //Columns that should not be pivoted        
            var _dynamicColumnCount = 2; // Columns which needs to be pivoted to form header            
            var _valueColumnCount = 1; //Columns that represent Actual value        
            var valueColumnIndex = 4; //Assuming index starts with 0;

            List<List<string>> headerInfo = new List<List<string>>();
            headerInfo.Add(new List<string> {"Product Three", "Item Ten"});
            headerInfo.Add(new List<string> {"Product Two", "Item Five"});
            headerInfo.Add(new List<string> {"Product Two", "Item Seven"});
            headerInfo.Add(new List<string> {"Product Two", "Item Nine"});
            headerInfo.Add(new List<string> {"Product One", "Item One"});
            headerInfo.Add(new List<string> {"Product One", "Item Two"});
            headerInfo.Add(new List<string> {"Product One", "Item Four"});
            headerInfo.Add(new List<string> {"Product One", "Item Six"});
            headerInfo.Add(new List<string> {"Product One", "Item Eight"});
            headerInfo.Add(new List<string> {"Product One", "Item Eleven"});
            headerInfo.Add(new List<string> {"Product Three", "Item Ten"});


            List<List<string>> data = new List<List<string>>();
            data.Add(new List<string> {"Global", "Europe", "Product One", "Item One", "579984.59"});
            data.Add(new List<string> {"Global", "North America", "Product One", "Item Two", "314586.73"});
            data.Add(new List<string> {"Global", "Asia", "Product One", "Item One", "62735.13"});
            data.Add(new List<string> {"Global", "Asia", "Product Two", "Item Five", "12619234.69"});
            data.Add(new List<string> {"Global", "North America", "Product Two", "Item Five", "8953713.39"});
            data.Add(new List<string> {"Global", "Europe", "Product One", "Item Two", "124267.4"});
            data.Add(new List<string> {"Global", "Asia", "Product One", "Item Four", "482338.49"});
            data.Add(new List<string> {"Global", "North America", "Product One", "Item Four", "809185.13"});
            data.Add(new List<string> {"Global", "Europe", "Product One", "Item Four", "233101"});
            data.Add(new List<string> {"Global", "Asia", "Product One", "Item Two", "120561.65"});
            data.Add(new List<string> {"Global", "North America", "Product One", "Item Six", "1517359.37"});
            data.Add(new List<string> {"Global", "Europe", "Product One", "Item Six", "382590.45"});
            data.Add(new List<string> {"Global", "North America", "Product One", "Item Eight", "661835.64"});
            data.Add(new List<string> {"Global", "Europe", "Product Three", "Item Three", "0"});
            data.Add(new List<string> {"Global", "Europe", "Product One", "Item Eight", "0"});
            data.Add(new List<string> {"Global", "Europe", "Product Two", "Item Five", "3478145.38"});
            data.Add(new List<string> {"Global", "Asia", "Product One", "Item Six", "0"});
            data.Add(new List<string> {"Global", "North America", "Product Two", "Item Seven", "4247059.97"});
            data.Add(new List<string> {"Global", "Asia", "Product Two", "Item Seven", "2163718.01"});
            data.Add(new List<string> {"Global", "Europe", "Product Two", "Item Seven", "2158782.48"});
            data.Add(new List<string> {"Global", "North America", "Product Two", "Item Nine", "72634.46"});
            data.Add(new List<string> {"Global", "Europe", "Product Two", "Item Nine", "127500"});
            data.Add(new List<string> {"Global", "North America", "Product One", "Item One", "110964.44"});
            data.Add(new List<string> {"Global", "Asia", "Product Three", "Item Ten", "2064.99"});
            data.Add(new List<string> {"Global", "Europe", "Product One", "Item Eleven", "0"});
            data.Add(new List<string> {"Global", "Asia", "Product Two", "Item Nine", "1250"});


        }
    }


Get this bounty!!!

#StackBounty: #c# #asp.net #sql-server #authentication #asp.net-membership admin users will be invalid in asp.net membership after a wh…

Bounty: 50

Our website uses Membership provider and has an admin panel that a number of users have access to it. the problem is admin Users can’t login after a while and when I debug login codes, “Membership.ValidateUser(username, password)” method condition results false. I can’t find the reason and also check the difference between valid and invalid users and can’t find any things.it should be noted when I comment the ValidateUser method, user can login. How can I solve this problem?

thanks.

Login code:

protected void btnSignIn_Click(object sender, EventArgs e)
{
    if (Membership.ValidateUser(txtEmail.Text, txtPassword.Text))
    {
        var member = Membership.GetUser(txtEmail.Text);
        if (member.IsLockedOut)
        {
            if (DateTime.Now.Subtract(member.LastLockoutDate).TotalMinutes > 10)
            {
                member.UnlockUser();
            }
            else
            {
                (Page as BasePage).Alert("Your account due to entering the wrong credentials more than 5 times, has been blocked, please right after 10 minutes to re-enter your user information.");
                return;
            }
        }

        if (Request.QueryString["ReturnUrl"] != null)
        {
            FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, false);
        }
        else
        {
            if (Roles.IsUserInRole(txtEmail.Text, SiteUtility.SiteRoles.admin.ToString()) || Roles.IsUserInRole(txtEmail.Text, SiteUtility.SiteRoles.adminl2.ToString()))
            {
                FormsAuthentication.SetAuthCookie(txtEmail.Text, false);
                Response.Redirect("/admin/");
            }
        }
    }
    else
    {
        if (Page is BasePage)
        {
            (Page as BasePage).Alert("Username or password is incorrect.");
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(typeof(Page), "alterror", "alert('Username or password is incorrect.');", true);
        }
    }
}

Membership provider config in web.config

<membership userIsOnlineTimeWindow="10" hashAlgorithmType="SHA1">
  <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" passwordFormat="Hashed" connectionStringName="CSConnectionString" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="2" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="ApplicationKaspid"/>
  </providers>
</membership>


Get this bounty!!!

#StackBounty: #c# #wpf #audio #clipboard WPF C# Copy Audio File To Clipboard

Bounty: 50

I am trying to copy an audio file to the clipboard in C# using a file path. The issue I am running into is that it is either not copying, or not copying correctly because it can not be pasted outside of the application.

Here is how I am trying to copy it to the clipboard:

b_array = File.ReadAllBytes(fileLocation);
Clipboard.Clear();
Clipboard.SetAudio(b_array);

the variable fileLocation in my testing equals something like: C:UsersbenMusicSampleskick_05.wav


Get this bounty!!!

#StackBounty: #c++ #architecture #lua Should I create a Lua wrapper classes for my C++ classes, or should I bind them directly?

Bounty: 50

I use LuaBridge, and I have a scene with an entity-component architecture, like this:

GameObjects have Transform, and can have Renderer, Rigidbody, Camera, LightSource, etc, and all of these classes have their corresponding methods.

  • Like GameObject has GetName, SetName, etc
  • Transform has GetPosition, SetPosition, etc
  • Renderer has SetTexture, SetMaterial, etc
  • And so on.

(If something is not clear, or there isn’t enough information, just tell me)

My question is, that which one is better, and what are the pros and cons, if I want to implement lua scripting, and I would like to achieve an API similar to this:

function update()
    local gameObject = this()
    local renderer = gameObject:GetRenderer()
    renderer:SetTexture("Brick")
    local rigidbody = gameObject:GetRigidbody()
    rigidbody:SetMass(10)
    local transform = gameObject:GetTransform()
    transform:SetPosition(1, 10, -5)
end

Solution A:

  • I bind every class directly to lua classes.
    • In this way I have to implement some extra scripting QoL methods for the classes, so no big deal.

    • Not so easy to see, whether a method is callable in Lua script, or only available in native code. (for example I need to name method XYZ LuaXYZ)

    • Methods which are only created so scripting is made easier is mixed with core functionality.

Solution B:

  • I create a wrapper class for every required class, like: Renderer -> RendererHandler, Transform -> Transform Handler, GameObject -> GameObjectHandler, etc
    • Lua and core functionality is separated, much easier to see what is the scripting API and what is not.
    • For every class I have to create another similar class which got a lot of methods, which are just calling the calling the same method in the wrapped class. Like GameObjectHandler’s GetName() just calls GameObject’s GetName()

Currently that’s all that came to my mind.

Thanks in advance.

Summary:

  • In my opinion, Solution B is the best. That is the easiest to handle, the most transparent, and the most separated.
  • But I got lots of new classes and new dependencies, which messes up my clean architecture. Solution A makes expanding functionality much easier to handle (I dont have to create a lua interface class for new components).

  • But error handling is worse, because I don’t have to care about if a scripter uses a nil (nullptr) value, (like a non existent component)

  • but if that happens due to my engine implementation I should have to take it very seriously. (And how can I signal whether a nullptr in a method ├ęs “dont care type” or “serious problem” type.

  • So currently I think, that the best solution is this:

    class GameObject {
       ...
    
       GetName()
       SetName()
    
       Lua_getName()
       Lua_setName()
    
       ...
    
  • I don’t have to create “lua interface” classes, and handle that mess that comes with it.
  • I directly bind the lua functions to the classes, but I create new methods in that class for scripting purposes.

  • For example I implement GetName() for “InEngine” functionality, and a Lua_getName() which is bound to lua functions and used only in scripts.

  • The problem here is that, yeah you can’t call InEngine methods from Lua because it’s not bound. But what about calling Lua_getName instead of GetName?

    • There is no compile check for that, and if the developer is tired and makes this mistake, it will be hell to debug that.


Get this bounty!!!