I'm new to Lua and Love2D, I did 2-3 simple games and I wanted to put them together. I did a window where you choose which game you want to play. It succeed; with a little problem. Two of my games use a ball. So both have a Ball.lua File. I use the require function to load the Ball file in each of my games. It works at first, I can play Game1, go back and play Game2 without any problem. But if I go back and want to play the Game1 again. His ball.lua File will not be required since require only load once. Then there will have an error since my game1 is trying to use my Game2's ball Class.
I wanted to know which solution would be best :
Just rename the files. (I would like to avoid it, feels hardcoding to me)
Use doFile. (I never used it, I don't even know if it would work)
Require the two Ball's Classes in my Main menu and pass it by parameter when loading each game (Don't know if it would work too)
If you want to see my code for more explanation, here's the link : https://github.com/cbelangerstpierre/Games/tree/main/Games
Thanks in advance !
As you know, require will only execute each file once. However it will also save the return value of the file so you can require the file as many times as you want and still get the same value.
In your Ball.lua files, make your Ball declarations local:
local Ball = Class{}
Then at the bottom of those files add:
return Ball
Then, change your main.lua files to store to the global Ball variable:
Ball = require "Atari-Breakout.Ball"
and
Ball = require("Switching-Ball.Ball")
Ideally, it's recommended to make all of your variables local and return tables from the files that you need to require.
Related
I'm trying to make game like "Duke Nukem 3D". I will have many maps in my game and each map will have it's own (and no more!) data files such as textures, sounds and so on, that's why I need to compress all these data files to one "map" file.
So, let's image that I want to test my maps one by one, and after compiling my code I want to test my first map with her textures and sounds, And when I type in my command line something like this: ./game_name "mymap.rce" or ./game_name "mymap.zip" my game must start with map what I typed and this map must have textures and sounds which I compressed with her.
You can download demo here.
To run demo you can type this for example: ./rce demo1.rce
So, I just made my archiver(without compress). If you need it, you can find it here.
I made a 3D tree in Maya and need MEL code to run in a for loop and generate as many trees as I want. Is there any way to convert a model made in Maya into MEL code that would rebuild the tree?
I can't just duplicate it because the script needs to generate the tree from scratch. Unfortunately, I cleared my history because it was messy, so I am looking for a way to generate the MEL code given just the geometry.
It is slightly unfortunate that you deleted the history. If you had not then you could have just built a script out if the history tree. But all is not lost, still i will explain how you can do this in case you do remake the history at some point.
The complexity of your history is never really a issue, at least when modeling. I would advice to not delete any history until your sure its of no use. Having a 1000 node history is not in any way slowing you down since most of it is inactive. Its only a problem once you enter animation even then its not necessarily a problem at all. Since the history deletion is a bit destructive its a good idea to save the scene when you are deleting big areas of history. So rule of thumb do not delete history and use the freeze transformation operation unless its really necessary (and it may be you never actually do this).
Another side remark: Copying stuff is still valid, unless like in this case there is a artificial limitation. The only time when this limitation is valid is if this is homework (in which case you may want to demonstrate that your willing to follow instruction). Doing a copy does not detract in any way the end result. Copying is mel (and all maya ascii files are mel of sorts).
Method 1: (when history is cleared)
You can reduce the problem to a normal rigging operation. What you do is you rig the tree that you built with bones, clusters and possibly blend shapes. Then just randomize the channels of your rig on each copy operation. The neat thing here is that the script can be easily extended with different base trees, or just about anything, just by making new separate rigs.
The bonus here is that you could now also easily animate the tree being blown by the wind etc.
This might feel like something outside the scope of the assignment. However a good MEL programmer does not really separate tasks. Using a node to do something is just as valid, if not more valid, as writing everything in code. Something like this demonstrates really thorough understanding of maya use and maya programming. On the other hand not all users are as enlightened (most are not).
Everything in Maya is or at least should be a rig. (the auxiliary to this is that your mel should strive to build a rig or you should use API to make nodes)
Method 2: (when history is cleared)
Chunk your result into pieces. Then randomize the chunk positions with L-system like rule based generator. It may seem counter intuitive to use a L-system with hand modeled pieces when the entire thing could be generated with a L-system.
But clunking allows for a very simple l-system to be built. The end result also retains the artistic integrity of the original in some ways that might be much more pleasing.
A slightly different version of this and method 3 is to make 2-3 overlapping set of branches in the model and then randomly delete branches for variation.
Method 3: (when history is cleared)
Cheat, well i would actually argue that in CG there's no such thing as cheating. Just copy the same tree about, alter its rotation ans scale. And randomize new shaders to your model (swap different leaf textures different color etc). When combined with even slight amount of rigginng approach can totally hide the fact that there is just one tree. Copies dont have to be all that exact they might be shaped with a lattice or something. This is actually pretty efficient, most people wouldn't notice.
Method 4: (when history is not cleared)
When you model something manually maya records this quite efficiently. The history can be turned into a script with little or no effort. The best kept secret. If you save this kind of scene as maya ascii then the maya ascii file is (almost) just mel and you can repeat this by adding variables to the stream to instrument it to mel. Beware tough that not all tools build meaningful history so point tweaks should be done on clusters instead on manual point tweaking that ends up in the shapes tweak array.
It is also possible to build the mel automatically with a mel script that checks for connections and values in nodes to reproduce the thing in code. The good thing is that you can readily introduce the instrumentation. Here's a really old version of code as giveaway (you need to handle the shaders and inputComponents for example):
/* jooConvertNodeNetworkToMelLadder.mel 0.0
Authors: Janne 'Joojaa' Ojala
Testing: Has known bugs, code deprecated, no bug reporting
Licence: Creative Commons Attribution-ShareAlike 3.0 Unported
About:
A deprecated early version of code generation it has some bugs and
is nowhere near perfect but you can have this code for the heck of
it. Main thing missing is that it does not check for selection
sets for nodes so you need to make those manually.
Install Instructions:
copy jooConvertNodeNetworkToMelLadder.mel to your maya script
directory
Usage:
Select node and run jooConvertNodeNetworkToMelLadder from mel
commandline.
Deprecated at 31.12.2006
*/
proc string generateAttrib(string $node, string $createNode,
string $attrib,string $varName){
string $return="";
if (getAttr($node + "." + $attrib) !=
getAttr($createNode + "." + $attrib))
$return = (" setAttr (" +
$varName + "+\"." + $attrib+"\") "+
getAttr($node + "." + $attrib) + ";\n");
return $return;
}
proc string doOneNode(string $nodeOrig,string $connections[]){
string $hist[]=`listConnections -c 1 -p 1 $nodeOrig`;
string $return="";
$type=`nodeType $nodeOrig`;
$varName=("$"+$nodeOrig);
$createNode=`createNode $type`;
$return=(" "+$varName+"=`createNode -n "+$nodeOrig+" "+$type+"`;\n");
if ($type != "mesh") {
for ($attrib in `listAttr -settable -multi -w -scalar $createNode`){
$return += generateAttrib($nodeOrig, $createNode,
$attrib, $varName);
}
}
delete $createNode;
for ($i=0;$i< size($hist);$i=$i+2){
if (size(`connectionInfo -dfs $hist[$i]`)){
string $node,$port,$type,$nodeOrig,$portOrig;
$node=`match "[^.]*" $hist[$i+1]`;
$port=`match "[.].*$" $hist[$i+1]`;
$nodeOrig=`match "[^.]*" $hist[$i]`;
$portOrig=`match "[.].*$" $hist[$i]`;
$connections[size($connections)]=
(" connectAttr -f ($" +
$nodeOrig + "+\"" + $portOrig + "\") ($" +
$node+"+\""+$port+"\");");
}
}
return $return;
}
global proc jooConvertNodeNetworkToMelLadder()
{
print "\n// jooConvertNodeNetworkToMelLadder result:\n{\n";
string $a[]={};
for ($node in `listHistory`)
print(`doOneNode $node $a`);
print $a;
print "}\n";
}
But this is all I have time for, hope this helps.
I've double-checked to see if this specific question has been asked before, and I was unable to find anything of use, soooo.....
I've managed to use my PNRG to store ten numbers in an array, but I don't know how to use them to 'persist' my dungeon floors. I've tried to figure out out to use pointers, but it's too confusing for my poor brain!
If this is already asked, just point me (heh, geddit? Point? Pointers? Well, I thought it was funny....) in the right direction!
Thanks in advance!
If you want your dungeon to persist after the player saves and closes the program, you'll have to take your map data, player state, and everything and save it to a file. And then load it from the file rather than generating it randomly at startup.
If you want your dungeon to persist, say, between floors that the player can travel up and down, it's still a valid idea to save the individual floors off to file and load them as needed. A side bonus that Nethack uses is that if the whole thing crashes, it can attempt to reconstruct the save from the last time you moved between floors.
Alternatively, you can simply have your dungeon consist of an ever growing vector, or a 3D array, complete with x,y, and z coordinates.
It's not so much a question about pointers as much as how to store data and where. New to programming or new to roguelike? Just use one big global array for a map and call it done.
(Also, PRNG not PNRG, pseudo-random number generator)
Please keep in mind that I am a TOTAL NOOB. I am not asking anyone to code my entire project, but I am easily lost in many cases. Your help and patience is much appreciated ...
My AS3 code looks something like this:
var totalFeatureImageDownloads:Number = 0; //total file size of all feature images, in bytes
var totalFeatureImageDownloaded:Number = 0; //total downloaded of all feature images, in bytes
for each(var featureimage:XML in xml.featureimages.imgurl)
{
trace(featureimage);
var featureImageRequest:URLRequest = new URLRequest(featureimage);
var featureImageLoader:URLLoader = new URLLoader(featureImageRequest);
totalFeatureImageDownloads = totalFeatureImageDownloads + featureImageLoader.bytesTotal;
trace(featureImageLoader.bytesTotal);
}
Currently I have 3 images in the XML file, and their URL's are traced properly. However, bytesTotal always equals 0. Also, I know that this loop creates 3 identically named URLRequest's and 3 identically named URLLoaders. I probably need to create 3 differently named ones.
I would like all the images to be downloaded simultaneously, and I need to calculate the combined file size for all three, along with the download status as a fraction (bytesLoaded / bytesTotal).
I have multiple scenarios like this, and am stuck until I get this finished. Your help is much appreciated. Cheers.
It is not possible to read the bytesTotal from a newly created URLLoader, because the client needs to connect to the web server first to get the size of the file to be downloaded. You need to listen for the first ProgressEvent.PROGRESS event sent by the URLLoader, once that event is sent the bytesTotal property is more likely to be accurate. I say "more likely" because it is not possible to get a total file size if the data is dynamically generated on the server, but in the general case where you download a file from the server it works.
I recognize the general scenario. There are libraries to aid with this, such as LoaderMax or BulkLoader. I personally use BulkLoader: https://github.com/arthur-debert/BulkLoader
Viewing/Searching java arrays and collections in the Eclipse Java debugger is tedious and time-consuming.
I tried this promising plugin (in alpha as of Aug 2012)
http://www.cvast.tuwien.ac.at/projects/visualdebugging/ArrayExplorer
But it freezes Eclipse for simple arrays beyond a few hundred elements.
I do use Detail formatters, but that still needs clicking on each element to see the values.
Are there any better ways to view this array/collection data?
Use the 'Expressions' tab.
There you can type in any number of expressions and have them evaluated in the current scope.
ie: collection.size(), collection.getValueAt(i), ect...
Eclipse > Preferences > Java > Debug >Detail Formatter
This may be close to what you are looking for. It is another tedious work to setup but once done you can see the value of objects in Expressions window.
Here is link to start
override toString method of your class and you will be able to see what you want to see. i'm attaching example to show you exactly that.
Even though i could not find a way to see them in nice table/array, i found a halfway workaround.
The solution is to define a static method in a throwaway class that takes the array as input and returns a string of concatenated values that one wants to quickly glance at. it could include the array index and newlines to view results formatted nicely. It can be fine tuned to print out only certain array indices to reduce clutter.
This static method can then be used in the watch area.