Jump to content

  • Log In with Google      Sign In   
  • Create Account


falconmick

Member Since 28 Aug 2011
Offline Last Active Nov 24 2012 01:57 AM
-----

#4930097 Why LUA Script ?

Posted by falconmick on 10 April 2012 - 09:28 PM

I've always thought of args as things that are passed into functions, not everyone is a whiz on this forum.

the downvote button is for not agreeing with someones opinion. That is all it was, I gave a first hand experience of how I have experienced LUA (:3) and even given a description of myself so they can understand why I would say what Ive said


lua needs time to be build in correctly, it is somthing that should be planned and implemented in segments.


#4929966 UDP or TCP?

Posted by falconmick on 10 April 2012 - 12:12 PM

If you require confirmation of data retrieved, i.e. you are making a synchronous system, TCP is a must
if you just need the latest data, as fast as posible, UDP is a better option.

for a RTS/turn based, skill shots is usually less of a requirement than having all the data you need. Also, TCP always seems to be efficient enough for a reliable connection speed.


#4929946 Why LUA Script ?

Posted by falconmick on 10 April 2012 - 11:34 AM

lua is great... and lua is horrible...
lua is great as once it is setup and going, it is wonderful, you can modify your game as it plays, not having to recompile and get to the state that you were testing
lua is horrible because setting it up can drive you insane. Well, at least me. Oh, and the documentation isn't always that helpful, for instance, lua_pcall(L, NumArgs, numRet, 0) when I first started using it I had my numArgs being the number of arguments the function needed, the documentation didn't specify specifically that the function call was also an argument, so it was failing on me. The documentation wasn't wrong, it just wasn't helpful enough for an impatient tiered student as of myself find understand it how it was meant to be.

I would recomend that you look into luabind... It can be hard to set up due to the lack of examples to follow and it can be made even harder if you can get impatient.
but once you have it implimented it can be really useful, I am currently working on my own luabinding, yes, it is driving me nuts, but the sheer flexibility it offers is what keeps me going at it.


#4929942 HELP: java game in command line

Posted by falconmick on 10 April 2012 - 11:26 AM

I would assume that if you are asking this that your knowledge in programming is fairly little (or maybe, you have never done Java)

As much as we would all love to start with the fun, I would recommend first learning C (if you don't already know it), not C++, but C.
after that, Java is a good language as it is an easy language to start with object orientation. this is some good theory, for learning java you can look at this... finally, once you know how to program in java to a high enough level maybe look into the theory behind the design of a game.. I was inable to find out how difficult making this would be, so I assumed it would be hard enough that making a proper design would be beneficial. you can look at that here

you could also have a look at this:
import java.io.*;
class RockPaperScissors {
BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) {
  RockPaperScissors RPS = new RockPaperScissors();
  System.out.println("Welcome to Rock, Paper, or Scissors!");
  System.out.print("Please enter the number of rounds you would like to play : ");
  int round = RPS.rounds();
  int user = 0;
  int computer = 0;
  for (int i = 0; i < round; i++) {
   if (RPS.choose(i + 1))
    user++;
   else
    computer++;
  }
  RPS.result(user, computer);
}

void result(int user, int computer) {
  System.out.println("RESULTS:");
  System.out.println("User wins : " + user);
  System.out.println("Computer wins : " + computer);
  if (user > computer)
   System.out.println("User wins the game!\n");
  else
   System.out.println("Computer wins the game!\n");
}

int rounds() {
  try {
   int temp = Integer.parseInt(BR.readLine());
   if (temp % 2 == 0)
    throw new Exception();
   return temp;
  }
  catch (Exception err) {
   System.out.print("Sorry, you need to enter an odd number. Please try again : ");
   return rounds();
  }
}

boolean choose(int val) {
  System.out.print("[Round " + val + "] Rock, Paper, or Scissors? : ");
  String input = "";
  try {
   input = BR.readLine();
  }
  catch(Exception err) {
  }
  if (input.equals("Rock"))
   return process(1, val);
  else if (input.equals("Paper"))
   return process(2, val);
  else if (input.equals("Scissors"))
   return process(3, val);
  else {
   System.out.println("Sorry, \"" + input + "\" is not a valid entry!\n");
   return choose(val);
  }
}

boolean process(int user, int val) {
  String[] hand = {"", "Rock", "Paper", "Scissors"};
  int comp = (int)(Math.random() * 3) + 1;
  if (user == comp) {
   System.out.println("Computer chooses " + hand[user] + ". It's a tie.\n");
   return choose(val);
  }
  else if (user == 1 && comp == 3) {
   System.out.println("Computer chooses " + hand[comp] + ". You win!\n");
   return true;
  }
  else if (user == 2 && comp == 3) {
   System.out.println("Computer chooses " + hand[comp] + ". You lose!\n");
   return false;
  }
  else if (user == 1 && comp == 2) {
   System.out.println("Computer chooses " + hand[comp] + ". You lose!\n");
   return false;
  }
  else if (user == 3 && comp == 2) {
   System.out.println("Computer chooses " + hand[comp] + ". You win!\n");
   return true;
  }
  else if (user == 2 && comp == 1) {
   System.out.println("Computer chooses " + hand[comp] + ". You win!\n");
   return true;
  }
  else {
   System.out.println("Computer chooses " + hand[comp] + ". You lose!\n");
   return false;
  }
}
}
source

I can't say if it works or not, but it is a good example as it shows nested loops and an easily implemented game.
I tend to find looking at someone else code easier to make my own.


#4928852 Is there an ACTUAL luabind tutorial

Posted by falconmick on 06 April 2012 - 12:23 PM

Nah, it is a requirement... I could do a bad job at it so our team doesn't fail, but I take pride in my work, so I wanted a useful system.
anyway, I think that all my problems came from not knowing enough about lua and calling
lua_close(L);

thinking it did something else

I should be able to get it working how I need now, once again, thanks for your help

edit:
doesn't everone know, it makes u feel better when you blame someone else Posted Image


#4928846 Need C++ Help

Posted by falconmick on 06 April 2012 - 11:59 AM

the real thing we need to know is, what experience do you have in programming...

if it's none, I wouldn't recomend C++ as a first language, It's amazing, but, it's best to start un object oriented and work your way up. Maybe learn C, then java (java next as it is allot more forgiving than C++ is)

this is a good starting point to learn C.

if you have experience in programming basics, then I can recommend a text book I used as a student.

C++ Programming:Program Design Including Data Structures

(ISBN-13:

9780538798099) (ISBN-10: 0538798092)



the best thing to do is write your own assignments, for example, make a data system for a library (store books, people, lending info in classes (try to keep in mind data abstraction, it will help you in this)) so that a user console can enter data into the system and check current loans/people/book status


#4928840 Is there an ACTUAL luabind tutorial

Posted by falconmick on 06 April 2012 - 11:36 AM

thanks for your help, I am fairly sure that the problem (I'm almost certain) that is was

lua_close()...


In my defence though.. I am attempting to learn how to set up lua binding with my only experience being fiddling with lua code in WoW addons.. I don't really count that though as everything I did was more writing lua, not implementing it. I just wish there was a better guide out there :\ and I sware I looked up every function I called and could never find

http://www.lua.org/m....html#lua_close.. I must just be blind...

The best way to learn lua and luabind I would say is NOT through beating your head against the wall as fast as possible till you break the wall down, probably stepping through the door (i.e. learn lua, then learn luabind) but I just don't have time... haha I should upload the work sheet we were given in which to learn lua and impliment it into a project.. the funniest thing about it was that the version of luabind they gave us was bugged + not statically linked... when ever you modified a file that had included luabind it would corrupt the link and you would have to clean/rebuild... so I had to learn how to build lua + boost + luabind... The worst part is that it is a requirement for the assignment, but when I ask my tutor/lector for help in lua/luabinding they couldn't, I had to ask my class mates who did it last semester (and they had just as much joy initially)

edit:
hahaha now I understand why I was getting access violations, lua had free'd up the space, but I still had a pointer to that space #DOH!#

edit 2:
it's sad that a random interwebs person is a better teacher than my teacher -.-
they should just fire the lecturer and the tutor guys and employ google full time

any particular reason for a -1 on this?
I am admitting my fault + thanking you?
:( you gotta understand I am stressing a lil atm

but I am defiantly gonna make a tutorial when I finish this unit, hell, if I help one person it will be worth it


#4928830 Is there an ACTUAL luabind tutorial

Posted by falconmick on 06 April 2012 - 11:15 AM

I would say my problem is more 10% inexperience 10%

attitude and 80% stress because the assignment (game engine) is due in a week...

I havn't been putting it off.. it's just a stupidly massive assignment, I've been working on for 2 months




#4928808 Is there an ACTUAL luabind tutorial

Posted by falconmick on 06 April 2012 - 09:46 AM

I'm no longer passing a lua_state to the constructor... I decided that that would be the problem 100 problems ago... still get errors -.-

Now I think it might be that putting it into a map is a bad idea, gonna try not using a map.


#4928727 Is there an ACTUAL luabind tutorial

Posted by falconmick on 06 April 2012 - 04:03 AM

seriously.. anybody out there with ANY knowledge of luabind PLEASE PLEASE help... I have no idea how it works and now I'm getting errors which are either me getting pissed off or luabind being a peice of *(@T... I have 2 lua states being held in a map... I used .find(instEnum)->second to access them.. but when ever I pass this back through a function it causes access violations

First-chance exception at 0x0009facd in LuaInstances.exe: 0xC0000005: Access violation reading location 0xfeeeff32.
Unhandled exception at 0x77df15ee in LuaInstances.exe: 0xC0000005: Access violation reading location 0xfeeeff32.

I know its probably somthing so soo simple.. but I am dead.. luabind is making me want to murder ducklings


#4928718 Is there an ACTUAL luabind tutorial

Posted by falconmick on 06 April 2012 - 03:23 AM

turns out error is hear:
luabind::module(L)
[
luabind::class_<CompCompiler>("CompCompiler")
				.def(luabind::constructor<lua_State>())
   .def("setSomeData",&CompCompiler::setSomeData)
				.def("setMoreData", &CompCompiler::setMoreData)
.def("getSomeData", &CompCompiler::getSomeData)
.def("getMoreData", &CompCompiler::getMoreData)
		 ];

.def(luabind::constructor<lua_State>())

originally the constructor TRIED to accept a lua_state in the constructor, I changed. sigh... the error message didn't help me at all

edit:
lol one problem fixed, another pop's its head up


#4928715 Is there an ACTUAL luabind tutorial

Posted by falconmick on 06 April 2012 - 03:08 AM

ive build a working program using these libraries before, I will though look at my other version which isn't statically linked

edit:

nope, that wasn't the problem, and both of these builds have worked in different situations

edit:
I think I know the problem, it is a static class, therefore accessing it's includes might cause derp


#4928703 Is there an ACTUAL luabind tutorial

Posted by falconmick on 06 April 2012 - 01:48 AM

btw, if anyone wants to try to help me, I get these more easy to read errors:


Error 1 error C2027: use of undefined type 'lua_State' g:\crsm-svn\luatesting\externallibraries\include\luabind\detail\call.hpp 293

Error 2 error C2664: 'void luabind::detail::construct_aux<Arity,T,Pointer,Signature>::operator ()(const luabind::adl::argument &,lua_State) const' : cannot convert parameter 2 from 'a1' to 'lua_State' g:\crsm-svn\luatesting\externallibraries\include\luabind\detail\call.hpp 294


#4928699 Is there an ACTUAL luabind tutorial

Posted by falconmick on 06 April 2012 - 01:35 AM

for instance... I cannot find a way in hell to fix this error:

CompCompiler.cpp
1>g:\crsm-svn\luatesting\externallibraries\include\luabind\detail\call.hpp(293): error C2027: use of undefined type 'lua_State'
1>		  g:\crsm-svn\luatesting\externallibraries\include\lua.h(50) : see declaration of 'lua_State'
1>		  g:\crsm-svn\luatesting\externallibraries\include\luabind\detail\call.hpp(89) : see reference to function template instantiation 'int luabind::detail::invoke_normal<F,boost::mpl::vector3<T0,T1,T2>,Policies>(lua_State *,const luabind::detail::function_object &,luabind::detail::invoke_context &,const F &,Signature,const Policies &,boost::mpl::long_<N>,boost::mpl::true_)' being compiled
1>		  with
1>		  [
1>			  F=luabind::detail::construct<construct_type,pointer,signature>,
1>			  T0=void,
1>			  T1=const luabind::adl::argument &,
1>			  T2=lua_State,
1>			  Policies=luabind::detail::null_type,
1>			  Signature=boost::mpl::vector3<void,const luabind::adl::argument &,lua_State>,
1>			  N=2
1>		  ]
.........
........

which is being caused by this class:
header:
#pragma once

#include <lua.hpp>
#include <luabind/luabind.hpp>

class CompCompiler
{
public:
CompCompiler();
~CompCompiler();
void setSomeData(int dataz);
void setMoreData(bool statezzz);
int getSomeData(){return(someData);};
bool getMoreData(){return(moreData);};
void setupLuaBinds(lua_State *L);
private:
int someData;
bool moreData;
};
implementation:
#include "CompCompiler.h"

CompCompiler::CompCompiler()
{
someData = 2;

moreData = true;
}

void CompCompiler::setupLuaBinds(lua_State *L)
{
luaL_openlibs(L);
luabind::open(L);

luabind::module(L)
[
luabind::class_<CompCompiler>("CompCompiler")
		.def(luabind::constructor<lua_State>())
   .def("setSomeData",&CompCompiler::setSomeData)
		.def("setMoreData", &CompCompiler::setMoreData)
.def("getSomeData", &CompCompiler::getSomeData)
.def("getMoreData", &CompCompiler::getMoreData)
	 ];

lua_close(L);
}


CompCompiler::~CompCompiler()
{
}

Now, the reason why I am getting this error is probably something trivial.. but as I have no knowledge in luabind I am hitting a brick wall.

I thought, hey maybe it's because inside of a constructor lua_state is unacceptable for some stupid reason, bummer, now my neat idea ain't gonna be as need as I wanted it to be, but when I changed my code (to what you see there) so that lua_state wasn't in the compiler, it was in a fully compiled class, it still gets the error -.-
so apparently atm luabind is angry at me for passing a lua_state... can you even pass a lua_state?

So I am stuck at a brick wall... I am trying to keep my LuaInstances class as abstract as possible (i.e. all it does is hold and distribute the states, the classes using them initiate their part in a given instance (yes I know, if I wanted to be fully abstract I would make a separate class for initiating the class being binded to luabind, but I can't be bothered) can you not do this?

I am trying to make it so that there are multiple instances of lua_state so that I can keep my lua states COMPLETLY seperate so that when who ever is writing the scripts, is writing the scripts, they only have access to a portion of the functions in my code for a given task.. I don't want somone who is changing key bindings having access to entity management -.-.. I considered namespaces, but people would (to the best of my knowledge) be able to access the functions/globals I don't want them having access to.


#4928538 Is there an ACTUAL luabind tutorial

Posted by falconmick on 05 April 2012 - 11:37 AM

I'm assuming the documentation isn't sufficient?


Not really... I am slowly getting a hold of it, but without other teams at my uni I wouldn't be able to do it.. the biggest thing I needed, luabind::globals has almost no info on it in the documentation, If I get to fully understand it I might make a guide (after this semester)




PARTNERS