string[] listboxItems = new string[] { };
for (int i = 0; i < lstMaleFirstName.Items.Count; i++)
{
listboxItems[i] = lstMaleFirstName.Items[i].ToString();
}
maleFirstNameArray.Add(listboxItems);
You get an OutOfRangeException because the listboxItems array basically has a size of 0, so when you go about trying to add items to it things get unhappy quickly. You should do:
string[] listboxItems = new string[lstMaleFirstName.Items.Count];
That should solve your problem.
[edit] Also, instead of doing:
maleFirstNameArray.Add(listboxItems);
You probably want:
maleFirstNameArray.AddRange(listboxItems);
[edit Mk II] Actually, there's no need for the temporary string array if all you want to do is add the items from the ListBox to the ArrayList. Just iterate through the items in the ListBox and add them straight to your ArrayList.
foreach(string lbItem in lstMaleFirstName.Items)
{
maleFirstNameArray.Add(lbItem);
}
The most important thing you have to understand is that Web Controls are nothing more than little chunks of HTML.
Everything between a Label and a Datagrid is just a block of HTML spit out onto the page.
Many simple controls have a CssClass property that can be assigned to them, and hand in hand with that, many simple controls represent just one sort of HTML tag (an asp:label is just a span tag, an asp:image is just an img tag). If CssClass doesn't float your boat, most web controls (or parts of web controls such as the ItemTemplate of a Datalist) support the Attributes.Add("name", "value") method where you can manually insert inline CSS rules.
The more complex controls, such as a datagrid, are a royal pain in the ass to use CSS effectively on. They have numerous different gears and bolts within them and you have to make a bunch of classes and know exactly where to put them.
The trick is to only use controls that play well with CSS. You tend to figure out which ones those are.
For complex databinding, I highly recommend sticking to asp:repeater unless you have a heavenly purpose for resorting to a more complex control like a datalist or datagrid.
A repeater is basically just an empty shell and allows you to specify your own CSS friendly/clean markup. The only thing it isn't good for is creating nested tables/lists in which case you want to bump things up to a datalist.
The only drawback is a repeater is a blank slate therefore if you want paging and sorting you have to write it from scratch and THAT is a pain in the ass.
Basically with styling .NET controls it all comes down to function vs. form vs. budget.
Hey, thanks for the information Jasconius. Realized I totally forgot to thank you for that. :P What you said definitely helped me understand the relationship between web controls and css a lot better. I'm still perusing google to try and find some code samples of css being applied to aspx pages, just as sort of a jump off point/seeing something that works in action, but haven't found anything good yet. Oh well, I'll just keep looking. You can find anything on google given enough time, right? :P Thanks again.
hey guys
i'm interested (sorta) in learning python. Not really surewhy, i just seem to get a kick out of programming. I did a semester of c++ in uni, and just recently wrote some ungodly 50 page long macro for work in excel that can take up to an hour to chug, so i've got a little experience.
My biggest demotivator is that i don't have any goal with python. I have no project wo work towards. Can you guys suggest anything?
Playing around with wireless stuff/bluetooth stuff would be neat.
hey guys
i'm interested (sorta) in learning python. Not really surewhy, i just seem to get a kick out of programming. I did a semester of c++ in uni, and just recently wrote some ungodly 50 page long macro for work in excel that can take up to an hour to chug, so i've got a little experience.
My biggest demotivator is that i don't have any goal with python. I have no project wo work towards. Can you guys suggest anything?
Playing around with wireless stuff/bluetooth stuff would be neat.
The most important thing you have to understand is that Web Controls are nothing more than little chunks of HTML.
Everything between a Label and a Datagrid is just a block of HTML spit out onto the page.
Many simple controls have a CssClass property that can be assigned to them, and hand in hand with that, many simple controls represent just one sort of HTML tag (an asp:label is just a span tag, an asp:image is just an img tag). If CssClass doesn't float your boat, most web controls (or parts of web controls such as the ItemTemplate of a Datalist) support the Attributes.Add("name", "value") method where you can manually insert inline CSS rules.
The more complex controls, such as a datagrid, are a royal pain in the ass to use CSS effectively on. They have numerous different gears and bolts within them and you have to make a bunch of classes and know exactly where to put them.
The trick is to only use controls that play well with CSS. You tend to figure out which ones those are.
For complex databinding, I highly recommend sticking to asp:repeater unless you have a heavenly purpose for resorting to a more complex control like a datalist or datagrid.
A repeater is basically just an empty shell and allows you to specify your own CSS friendly/clean markup. The only thing it isn't good for is creating nested tables/lists in which case you want to bump things up to a datalist.
The only drawback is a repeater is a blank slate therefore if you want paging and sorting you have to write it from scratch and THAT is a pain in the ass.
Basically with styling .NET controls it all comes down to function vs. form vs. budget.
Hey, thanks for the information Jasconius. Realized I totally forgot to thank you for that. :P What you said definitely helped me understand the relationship between web controls and css a lot better. I'm still perusing google to try and find some code samples of css being applied to aspx pages, just as sort of a jump off point/seeing something that works in action, but haven't found anything good yet. Oh well, I'll just keep looking. You can find anything on google given enough time, right? :P Thanks again.
Well if you understand how CSS works then here's a few basic examples.
An ASP Label is a span tag here's the translation
<asp:label id="lblTest" runat="server" text="This is a label" cssclass="date" />
Translates to
<span id="(UNIQUE ASP.NET ID)" class="date">This is a label</span>
Note how the ID is always a unique ASP.NET identifier, don't ever try to apply styles to ASP.NET controls based on ID unless you have a damn good reason to, because it's very fickle and considered a hack.
So, to apply a style to this asp:label in your stylesheet you have
But be careful because doing that would affect all the span tags in your page. Usually doing this you would reference a container that the span was contained in to make it more specific, so lets say all your labels in the footer of your page was using that style it would be
That works for basic examples, but if you have a more complex datalist with headers, etc, then you have to drill down. I don't have visual studio in front of my right now so I am guessing at the actual attribute names, but you should be able to find them.
<asp:datalist id="dlSomeName" runat="server" CssClass="tableclass" ItemStyle-CssClass="tableitem" HeaderStyle-CssClass="tableheader">
<headertemplate>
<!-- Header Controls go here -->
</headertemplate>
<itemtemplate>
<!-- Databound controls go here -->
</itemtemplate
</asp:datalist>
that will render out as
<table id="(UNIQUE ASP.NET ID)" class="tableclass">
<tr>
<td class="tableheader">
This is the header item
</td>
</tr>
<tr>
<td class="tableitem">
This is Item 1
</td>
</tr>
<tr>
<td class="tableitem">
This is Item 2
</td>
</tr>
</table>
So all your td's have 10px padding because they all inherit the class from the overall datalist class, but then your individual items have their own unique class to apply specific styles.
hey guys
i'm interested (sorta) in learning python. Not really surewhy, i just seem to get a kick out of programming. I did a semester of c++ in uni, and just recently wrote some ungodly 50 page long macro for work in excel that can take up to an hour to chug, so i've got a little experience.
My biggest demotivator is that i don't have any goal with python. I have no project wo work towards. Can you guys suggest anything?
Playing around with wireless stuff/bluetooth stuff would be neat.
SmasherStarting to get dizzyRegistered Userregular
edited March 2008
I'm not familiar with Javascript, but if it's similar to most other languages \ is an escape character. If it weren't there the < would be treated as a Javascript character rather than a character in the html string, which would presumably cause a syntax error.
I'm not familiar with Javascript, but if it's similar to most other languages \ is an escape character. If it weren't there the < would be treated as a Javascript character rather than a character in the html string, which would presumably cause a syntax error.
Right, but there's already a \ there.
edit: here's a visual to help: Ok, the forward slashes are delimiters. Think of them as quotes as you would see around a normal string. The g is best described as a parameter -- notice how it comes after the delimiter. It signifies that the pattern is to be looked for multiple times throughout the string, not just once. The backslash in green is an escape character for the less than, also in green.
That leaves the other \, which is there... why, exactly?
Holy shit dude, I wasn't expecting such a detailed explanation. I very much appreciate it though. This is pretty much exactly the kind of thing I was looking for, so thank you thank you thank you. Not to mention you explained it all in a very clear manner. Hell, you were clearer than a few of my teachers. :P I'm really glad you gave a datalist example, since we've been using gridview's like crazy so far this semester. Shouldn't be too much difference.
We've got a lab coming out next week where we have to create an order system, with a shopping cart and all that fun stuff. I wasn't looking forward to it much, but now I kinda can't wait to do it. I'll bang the code out quick and spend the rest of my time tinkering around adding css to it. Hopefully I can make it look a lot less haggard than my other labs so far. :P
OK, so I don't know if this is "beginner", but it's bugging the hell out of me :P
I'm writing a new app in ASP .NET, using Framework 3.5 with a healthy dose of AJAX. At seemingly random points throughout using the program, I get this error:
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Now, I definitely don't want to disable event validation. I also don't see anywhere I am sending postback/callback event parameters from a different control than the one that rendered them. Anyone seen this before and have an idea of the cause? I am using some asynchronous javascript as well as server-side events to handle different interactions.
[Re: C#] One thing I'd like to ask is; I see a lot of animation examples, for making things rotate or fade in and out, and so on, and they're often just a time counter plugged into a sine function. Is that the best way to go about things which are visual and time dependent? Moving a box onto the screen in a way which is more organic, for example - coming in fast and slowing down to stop right where you want it.
Here's a beginner and a related advanced question:
I've often heard of people combining languages in a single project or creating a wrapper to use OpenGL in C# and other such things where somehow you can magically get access in a project to call functions that are not provided by the language's default API.
A recent example is I see Aquaria lets you use LUA scripting to control behavior of nodes (and other things) in mods, by implementing some functions that Aquaria calls and providing some functions for you to use to manipulate the game. But I'm pretty sure Aquaria was written in C++, so how do they get those two things to talk to each other? (How do they get Aquaria to run scripts that may or may not be there for that matter?) I'm currently working on writing a rogue-like in Python, and I'm at a complete loss for how to design my game logic so that it can be manipulated with as much flexibility as possible by spells and such. I want adding new abilities, items, spells and monsters to the game to be as trivial as writing a new python script (don't see why I should use LUA if I'm already using a pretty simple interpreted language) that provides some attributes and can call some game logic functions and throwing it in the right folder. (This is not so much for modders as for my own sanity when I start adding content to the game after I've got the engine where I want it.)
Got a little off the main issue there, but how do people work this kind of magic, how does a mapping or wrapper work, how can you magically call what I assume is a C API in C# (as is the case with OpenGL wrappers I have seen)? How does something like PyObjectiveC work, where I believe it provides access to Cocoa API functionality in Python?
(Also, having nothing to do with my basic question here, but if anyone can offer advice on how I should architect my GameLogic class to provide both an API for abilities and spells and AI's and enforce gameplay flow and react to input I would be really grateful. Concerns include what should be in what class and how new stuff should be added to the game. I simply don't have a starting point. I read gamedev web sites, but they have this problem where they either give you really half-assed beginner advice or talk about advanced stuff that I have no clue about and try to sell you books.)
The quick answer: You can call other functions/methods from C/C++ DLL's in C# using Platform Invoke (P/Invoke). Basically all you have to do is point the C# code to the DLL, tell it what entry point you're wanting to use (method name), and as long as you can define a compatible datatype for what the method takes you should be good.
Or is that not what you were asking?
Here's a P/I sample. It uses shell32.dll in Windows to retrieve the icon of the program that is associated with the name of a file you pass:
[DllImport("Shell32.dll")]
private static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
private struct SHFILEINFO
{
public IntPtr hIcon;
public IntPtr iIcon;
public uint dwAtrributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
};
private const uint ICON_SMALL = 0x1;
private const uint ICON_LARGE = 0x0;
/// <summary>
/// Gets the icon for the program associated with the file.
/// </summary>
/// <param name="iFile">The file.</param>
/// <param name="iGetLarge">Return the large or small version of the icon.</param>
/// <returns>A System.Drawing.Icon object of the program associated with the given file.</returns>
public static Icon GetFileIcon(string iFile, bool iGetLarge)
{
if (!File.Exists(iFile))
{
return null;
}
SHFILEINFO fileInfo = new SHFILEINFO();
if (! iGetLarge)
{
SHGetFileInfo(iFile, 0, ref fileInfo, (uint)Marshal.SizeOf(fileInfo), 0x100 | ICON_SMALL);
}
else
{
SHGetFileInfo(iFile, 0, ref fileInfo, (uint)Marshal.SizeOf(fileInfo), 0x100 | ICON_LARGE);
}
return Icon.FromHandle(fileInfo.hIcon);
}
[Re: C#] One thing I'd like to ask is; I see a lot of animation examples, for making things rotate or fade in and out, and so on, and they're often just a time counter plugged into a sine function. Is that the best way to go about things which are visual and time dependent? Moving a box onto the screen in a way which is more organic, for example - coming in fast and slowing down to stop right where you want it.
It sounds like you're looking at an easing function which creates a smoother transition or movement than a linear change over time. If you use a box moving from one place to another as an example, one type of easing would be to start out fast but slow down as it moves into place instead of having it abruptly stop. A google search for easing functions will find tons.
I guess that makes sense, and would apply to other such situations as well, thanks! I was asking mostly because I was curious.
There's also a way to do it for classes, you just do it from the other end.
Now, I'm not familiar enough with C++/CLI to actually show you some code, but what you'd basically do is take an instance of the C++ class (or struct) in question, wrap it up inside a C++/CLI managed class, compile to an assembly, add to your project, and bam, you've got it.
*****EDIT*****
I came up with a working solution.
*****EDIT*****
I am using perl to do some data manipulation on some text files. The files have roughly this format.
[Section 1]
{
***Lines of data***
}
[Section 2]
{
***Different Lines of data***
}
etc.....
The formatting is as above with the specific brackets in the locations shown. Each section of data will have to be edited slightly differently than the others. I want to know a good way for the code to read the file and know what section it is in so that the appropriate changes can be made. Perl does a great job of mindlessly going through a file and changing each line without knowing (or caring) where it is. I just want to know how to make it aware of its location. I can handle everything else, I just need to know how to plot the logic for this out first.
as a pet project, can i use python to manipulate file names in windows?
for work, i manage drawing files for several projects
we get several hundred for each project, and each drawing for each project will go through several revisions.
each drawing is a seperate pdf
the naming convention goes something like xy-4502_rb where rb is the revision number, and goes from a-some letter, then from 0-inifinty. There are often times i'd like to move/copy these files automatically if the drawing has been superceeded (rb and rc exist in the same directory, i would want to copy rb to my superceedeed folder) and i'd also lke to maniupulate the drawing name so that STAMPED xy-4505_rb would be xy-4505_rb STAMPED so that they organize nicer. Can anyone point me in the right direction?
as a pet project, can i use python to manipulate file names in windows?
for work, i manage drawing files for several projects
we get several hundred for each project, and each drawing for each project will go through several revisions.
each drawing is a seperate pdf
the naming convention goes something like xy-4502_rb where rb is the revision number, and goes from a-some letter, then from 0-inifinty. There are often times i'd like to move/copy these files automatically if the drawing has been superceeded (rb and rc exist in the same directory, i would want to copy rb to my superceedeed folder) and i'd also lke to maniupulate the drawing name so that STAMPED xy-4505_rb would be xy-4505_rb STAMPED so that they organize nicer. Can anyone point me in the right direction?
will i need to run these thingy's in python, or is creating a windows executable even close to an option?
You'll need to install Python to develop it, but you can use distutils and py2exe to create a Win32 executable of the finished script.
EDIT: if this is some sort of corporate thing, or if you plan to write more scripts in the future, I advise just installing Python on all the computers that will run them.
will i need to run these thingy's in python, or is creating a windows executable even close to an option?
You'll need to install Python to develop it, but you can use distutils and py2exe to create a Win32 executable of the finished script.
EDIT: if this is some sort of corporate thing, or if you plan to write more scripts in the future, I advise just installing Python on all the computers that will run them.
py2exe plus a good nsis script will be able to create a one click exe that will self contain everything it needs, so no need for install.
python should have no problem doing this, since you basically are just asking to use os.walk, and some os.path commands. The only thing I would watch out for is some of the path commands expect unix slashes only so you might have to do some preprocessing.
I had to take a few years off from my programing exploits of some minor web stuff (Flash, mostly), a smidge of Java and C#, and today I would like to start my quest on learning Python, as it seems to be damn near the most handy thing in the world.
Anyone care to point me in the way of a good IDE and maybe some tutorials?
I had to take a few years off from my programing exploits of some minor web stuff (Flash, mostly), a smidge of Java and C#, and today I would like to start my quest on learning Python, as it seems to be damn near the most handy thing in the world.
Anyone care to point me in the way of a good IDE and maybe some tutorials?
The only IDE I can find is pydev for Eclipse, which is kind of a pain in the ass to set up but seems to work. Every time I click "run" it prompts me for a VM though, which is fucking annoying.
I haven't found a Windows plain text editor that I like. Notepad++ has great code hilighting & stuff, but it only manages documents in a horizontal tab bar, which is fucking retarded if you have a project of any size at all. TextPad is not free, and has shitty unantialiased text rendering, making me wonder why you would pay for it.
TextMate and TextWrangler are the only OS X solutions of any merit that I can find.
As for tutorials, I've been working from a combination of the free "Dive Into Python" book and the official documentation (which has a tutorial section somewhere with a nice TOC featuring all the basics).
will i need to run these thingy's in python, or is creating a windows executable even close to an option?
You'll need to install Python to develop it, but you can use distutils and py2exe to create a Win32 executable of the finished script.
EDIT: if this is some sort of corporate thing, or if you plan to write more scripts in the future, I advise just installing Python on all the computers that will run them.
py2exe plus a good nsis script will be able to create a one click exe that will self contain everything it needs, so no need for install.
python should have no problem doing this, since you basically are just asking to use os.walk, and some os.path commands. The only thing I would watch out for is some of the path commands expect unix slashes only so you might have to do some preprocessing.
so i'm having a hard time understanding what they mean by "path" and stuff like that.
So, these fancy new spriteFonts are fine and dandy, but I want to do something... unorthadox with them
I need to somehow let the user enter a string, then create a 2d array with width (in pixels) that that string would become when run through the spritefont dealy, and height being the height of the highest letter. Then I need to fill this array with a 1 wherever the image is black and a 0 wherever it's white.
So, for example, the word LOL
Would end up (roughly, using a small blocky font) in the array as
100010010 100101010 100101010 110010011
This array will then become that font, but in 3d little cubes.
A path is just a filename. In windows it consists of a drive, dirname, and basename. In UNIX, only dirname + basename. I don't know of any functions that require UNIX-style paths even on Windows.
For example, if you wanted to list all the files and directories in C:\, you'd execute "os.listdir ('C:\\')". Double backslashes are required for Windows-style paths. It is possible to use raw strings for that, but I advise against it because some of their behavior is not obvious when used for paths. For example, a raw string cannot end with a single backslash.
So, these fancy new spriteFonts are fine and dandy, but I want to do something... unorthadox with them
I need to somehow let the user enter a string, then create a 2d array with width (in pixels) that that string would become when run through the spritefont dealy, and height being the height of the highest letter. Then I need to fill this array with a 1 wherever the image is black and a 0 wherever it's white.
So, for example, the word LOL
Would end up (roughly, using a small blocky font) in the array as
100010010 100101010 100101010 110010011
This array will then become that font, but in 3d little cubes.
Any help deserves mad props. Thanks.
Well with a combination of System.Text and System.Drawing you can create Bitmaps from text input.
Then you could take the resultant bitmap and analyze each bit for it's color and then create a matrix or what have you of 0's and 1's.
But that array would gigantic (one entry per pixel) so you'd have to think of some way to shrink it down to the right size, say, for every 5 adjacent black pixels only do a single 1.
I have another XNA question.
Currently I'm messing around trying to create a simple little 2D sprite game. I've been reading some tutorials and as far as most of them get with 2D is just drawing a sprite to the screen. They then either want to jump right into making a basic physics engine or into 3D.
What I need to know is what is the best way "i.e. best practice" for taking a sprite off the screen. What I mean is, lets say I have SpriteA and lets say SpriteA is the sprite for a giant enemy crab or something. Lets also say that I hit the weak spot on SpriteA for massive damange and killed the crab. Now that the grab is dead I don't want to draw SpriteA to the screen anymore. So do I just not call the draw method or is there some kind of content unload method I should be calling?
LittleBoots on
Tofu wrote: Here be Littleboots, destroyer of threads and master of drunkposting.
I have another XNA question.
Currently I'm messing around trying to create a simple little 2D sprite game. I've been reading some tutorials and as far as most of them get with 2D is just drawing a sprite to the screen. They then either want to jump right into making a basic physics engine or into 3D.
What I need to know is what is the best way "i.e. best practice" for taking a sprite off the screen. What I mean is, lets say I have SpriteA and lets say SpriteA is the sprite for a giant enemy crab or something. Lets also say that I hit the weak spot on SpriteA for massive damange and killed the crab. Now that the grab is dead I don't want to draw SpriteA to the screen anymore. So do I just not call the draw method or is there some kind of content unload method I should be calling?
Just don't draw the sprite to the screen anymore. The only thing that might need to be unloaded is the sprite data itself, but
1. It'll be unloaded when the program ends.
2. You'll probably want to keep it incase you need to use it again without having to load it again.
If you need to get rid of it before you call Content.Unload(), you can do Texture2D.Dispose(), which should release its unmanaged resources (and will cause an error if you try and draw it after that).
I have another XNA question.
Currently I'm messing around trying to create a simple little 2D sprite game. I've been reading some tutorials and as far as most of them get with 2D is just drawing a sprite to the screen. They then either want to jump right into making a basic physics engine or into 3D.
What I need to know is what is the best way "i.e. best practice" for taking a sprite off the screen. What I mean is, lets say I have SpriteA and lets say SpriteA is the sprite for a giant enemy crab or something. Lets also say that I hit the weak spot on SpriteA for massive damange and killed the crab. Now that the grab is dead I don't want to draw SpriteA to the screen anymore. So do I just not call the draw method or is there some kind of content unload method I should be calling?
Just don't draw the sprite to the screen anymore. The only thing that might need to be unloaded is the sprite data itself, but
1. It'll be unloaded when the program ends.
2. You'll probably want to keep it incase you need to use it again without having to load it again.
If you need to get rid of it before you call Content.Unload(), you can do Texture2D.Dispose(), which should release its unmanaged resources (and will cause an error if you try and draw it after that).
Good stuff, thanks.
LittleBoots on
Tofu wrote: Here be Littleboots, destroyer of threads and master of drunkposting.
I have another XNA question.
Currently I'm messing around trying to create a simple little 2D sprite game. I've been reading some tutorials and as far as most of them get with 2D is just drawing a sprite to the screen. They then either want to jump right into making a basic physics engine or into 3D.
What I need to know is what is the best way "i.e. best practice" for taking a sprite off the screen. What I mean is, lets say I have SpriteA and lets say SpriteA is the sprite for a giant enemy crab or something. Lets also say that I hit the weak spot on SpriteA for massive damange and killed the crab. Now that the grab is dead I don't want to draw SpriteA to the screen anymore. So do I just not call the draw method or is there some kind of content unload method I should be calling?
Just don't draw the sprite to the screen anymore. The only thing that might need to be unloaded is the sprite data itself, but
1. It'll be unloaded when the program ends.
2. You'll probably want to keep it incase you need to use it again without having to load it again.
If you need to get rid of it before you call Content.Unload(), you can do Texture2D.Dispose(), which should release its unmanaged resources (and will cause an error if you try and draw it after that).
Good stuff, thanks.
On the subject of this, does C# have support for destructors?
I have another XNA question.
Currently I'm messing around trying to create a simple little 2D sprite game. I've been reading some tutorials and as far as most of them get with 2D is just drawing a sprite to the screen. They then either want to jump right into making a basic physics engine or into 3D.
What I need to know is what is the best way "i.e. best practice" for taking a sprite off the screen. What I mean is, lets say I have SpriteA and lets say SpriteA is the sprite for a giant enemy crab or something. Lets also say that I hit the weak spot on SpriteA for massive damange and killed the crab. Now that the grab is dead I don't want to draw SpriteA to the screen anymore. So do I just not call the draw method or is there some kind of content unload method I should be calling?
Just don't draw the sprite to the screen anymore. The only thing that might need to be unloaded is the sprite data itself, but
1. It'll be unloaded when the program ends.
2. You'll probably want to keep it incase you need to use it again without having to load it again.
If you need to get rid of it before you call Content.Unload(), you can do Texture2D.Dispose(), which should release its unmanaged resources (and will cause an error if you try and draw it after that).
Good stuff, thanks.
On the subject of this, does C# have support for destructors?
Kinda, but from what I've read its advised that beginners not mess with them and just create a Initialize method in your class instead to be called from the Initialize method of Game1 (as far as XNA goes). But I think all constructors and destructs are just overloads of the base class of all classes or something.
EDIT: Here is a snip from the msdn:
"If the class does not have a constructor, a default parameterless constructor is automatically generated for you and the default values are used to initialize the object fields"
I believe the same is true for destructors.
LittleBoots on
Tofu wrote: Here be Littleboots, destroyer of threads and master of drunkposting.
Posts
That should solve your problem.
[edit] Also, instead of doing:
You probably want:
[edit Mk II] Actually, there's no need for the temporary string array if all you want to do is add the items from the ListBox to the ArrayList. Just iterate through the items in the ListBox and add them straight to your ArrayList.
foreach(string lbItem in lstMaleFirstName.Items) { maleFirstNameArray.Add(lbItem); }I've gone with the edit 2 option; seems to work, thanks. And yeah, I know what AddRange is for, but in this case I need an array of other arrays.
Ah yes that code is much more simple than mine. Thank you very much for all the help, I really appreciate it!
Hey, thanks for the information Jasconius. Realized I totally forgot to thank you for that. :P What you said definitely helped me understand the relationship between web controls and css a lot better. I'm still perusing google to try and find some code samples of css being applied to aspx pages, just as sort of a jump off point/seeing something that works in action, but haven't found anything good yet. Oh well, I'll just keep looking. You can find anything on google given enough time, right? :P Thanks again.
i'm interested (sorta) in learning python. Not really surewhy, i just seem to get a kick out of programming. I did a semester of c++ in uni, and just recently wrote some ungodly 50 page long macro for work in excel that can take up to an hour to chug, so i've got a little experience.
My biggest demotivator is that i don't have any goal with python. I have no project wo work towards. Can you guys suggest anything?
Playing around with wireless stuff/bluetooth stuff would be neat.
Turns out I was wrong! Since I'm trying to add to an array in an ArrayList, rather than just to the ArrayList itself. Back to the drawing board.
Python + wiimote should provide hours of fun.
Well if you understand how CSS works then here's a few basic examples.
An ASP Label is a span tag here's the translation
Translates to
Note how the ID is always a unique ASP.NET identifier, don't ever try to apply styles to ASP.NET controls based on ID unless you have a damn good reason to, because it's very fickle and considered a hack.
So, to apply a style to this asp:label in your stylesheet you have
.date { font-size:10px; color:#ff0000; font-style:italic; }This makes your asp:label control 10 pixel font, red in color, and italic.
Also, because a label is always a span tag, you could also do something like
span { font-size:10px; color:#ff0000; font-style:italic; }But be careful because doing that would affect all the span tags in your page. Usually doing this you would reference a container that the span was contained in to make it more specific, so lets say all your labels in the footer of your page was using that style it would be
#footer span { font-size:10px; color:#ff0000; font-style:italic; }where #footer is the ID of your footer container div.
That's a simple solution, labels are childs play.
A more common, harder one is the fucking asp:datalist, and by proxy, asp:datagrid and asp:gridview.
We will use datalist just because it's the easiest of these data controls.
An asp:datalist by default generates a table, where each cell in the table represents a dataitem of your datasource.
So, lets say you have 2 data items in this datalist. The datalist control looks like
<asp:datalist id="dlSomeName" runat="server" CssClass="tableclass"> <itemtemplate> <!-- Databound controls go here --> </itemtemplate </asp:datalist>that will render out as
<table id="(UNIQUE ASP.NET ID)" class="tableclass"> <tr> <td> This is Item 1 </td> </tr> <tr> <td> This is Item 2 </td> </tr> </table>Now with your CSS you can do something like this
.tableclass { width:400px; } .tableclass td { padding:10px; }That works for basic examples, but if you have a more complex datalist with headers, etc, then you have to drill down. I don't have visual studio in front of my right now so I am guessing at the actual attribute names, but you should be able to find them.
<asp:datalist id="dlSomeName" runat="server" CssClass="tableclass" ItemStyle-CssClass="tableitem" HeaderStyle-CssClass="tableheader"> <headertemplate> <!-- Header Controls go here --> </headertemplate> <itemtemplate> <!-- Databound controls go here --> </itemtemplate </asp:datalist>that will render out as
<table id="(UNIQUE ASP.NET ID)" class="tableclass"> <tr> <td class="tableheader"> This is the header item </td> </tr> <tr> <td class="tableitem"> This is Item 1 </td> </tr> <tr> <td class="tableitem"> This is Item 2 </td> </tr> </table>Now with your CSS you can do something like this
.tableclass { width:400px; } .tableclass td { padding:10px; } .tableitem { background-color:#fff; } .tableheader { background-color:#00ff00; }So all your td's have 10px padding because they all inherit the class from the overall datalist class, but then your individual items have their own unique class to apply specific styles.
I hope this makes sense.
....
explain?
So I just came across this function looking for something to strip tags and special characters from strings on the internets:
function stripHtml(s) { return s.replace(/\\&/g,'&').replace(/\\</g,'<'). replace(/\\>/g,'>').replace(/\\t/g,' '). replace(/\\n/g, '<br />'); }...but, isn't it wrong? There's an extra backslash in each regex pattern, isn't there? IE, /\\</g should be /\</g, shouldn't it?
Or in other words: why is the backslash I've highlighted in red required?
I'M A TWITTER SHITTER
Right, but there's already a \ there.
edit: here's a visual to help:
Ok, the forward slashes are delimiters. Think of them as quotes as you would see around a normal string.
The g is best described as a parameter -- notice how it comes after the delimiter. It signifies that the pattern is to be looked for multiple times throughout the string, not just once.
The backslash in green is an escape character for the less than, also in green.
That leaves the other \, which is there... why, exactly?
I'M A TWITTER SHITTER
You also don't need to escape <, > and & in regexes.
Ah, I was wondering about that too. & doesn't seem to be a symbol you'd really need to escape.
Guess I just ran across a bad tutorial then? *shrug*
I'M A TWITTER SHITTER
Holy shit dude, I wasn't expecting such a detailed explanation. I very much appreciate it though. This is pretty much exactly the kind of thing I was looking for, so thank you thank you thank you. Not to mention you explained it all in a very clear manner. Hell, you were clearer than a few of my teachers. :P I'm really glad you gave a datalist example, since we've been using gridview's like crazy so far this semester. Shouldn't be too much difference.
We've got a lab coming out next week where we have to create an order system, with a shopping cart and all that fun stuff. I wasn't looking forward to it much, but now I kinda can't wait to do it. I'll bang the code out quick and spend the rest of my time tinkering around adding css to it. Hopefully I can make it look a lot less haggard than my other labs so far. :P
Thanks again!
I'm writing a new app in ASP .NET, using Framework 3.5 with a healthy dose of AJAX. At seemingly random points throughout using the program, I get this error:
Now, I definitely don't want to disable event validation. I also don't see anywhere I am sending postback/callback event parameters from a different control than the one that rendered them. Anyone seen this before and have an idea of the cause? I am using some asynchronous javascript as well as server-side events to handle different interactions.
Anyone have any advice?
I've often heard of people combining languages in a single project or creating a wrapper to use OpenGL in C# and other such things where somehow you can magically get access in a project to call functions that are not provided by the language's default API.
A recent example is I see Aquaria lets you use LUA scripting to control behavior of nodes (and other things) in mods, by implementing some functions that Aquaria calls and providing some functions for you to use to manipulate the game. But I'm pretty sure Aquaria was written in C++, so how do they get those two things to talk to each other? (How do they get Aquaria to run scripts that may or may not be there for that matter?) I'm currently working on writing a rogue-like in Python, and I'm at a complete loss for how to design my game logic so that it can be manipulated with as much flexibility as possible by spells and such. I want adding new abilities, items, spells and monsters to the game to be as trivial as writing a new python script (don't see why I should use LUA if I'm already using a pretty simple interpreted language) that provides some attributes and can call some game logic functions and throwing it in the right folder. (This is not so much for modders as for my own sanity when I start adding content to the game after I've got the engine where I want it.)
Got a little off the main issue there, but how do people work this kind of magic, how does a mapping or wrapper work, how can you magically call what I assume is a C API in C# (as is the case with OpenGL wrappers I have seen)? How does something like PyObjectiveC work, where I believe it provides access to Cocoa API functionality in Python?
(Also, having nothing to do with my basic question here, but if anyone can offer advice on how I should architect my GameLogic class to provide both an API for abilities and spells and AI's and enforce gameplay flow and react to input I would be really grateful. Concerns include what should be in what class and how new stuff should be added to the game. I simply don't have a starting point. I read gamedev web sites, but they have this problem where they either give you really half-assed beginner advice or talk about advanced stuff that I have no clue about and try to sell you books.)
Or is that not what you were asking?
Here's a P/I sample. It uses shell32.dll in Windows to retrieve the icon of the program that is associated with the name of a file you pass:
[DllImport("Shell32.dll")] private static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags); private struct SHFILEINFO { public IntPtr hIcon; public IntPtr iIcon; public uint dwAtrributes; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string szDisplayName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] public string szTypeName; }; private const uint ICON_SMALL = 0x1; private const uint ICON_LARGE = 0x0; /// <summary> /// Gets the icon for the program associated with the file. /// </summary> /// <param name="iFile">The file.</param> /// <param name="iGetLarge">Return the large or small version of the icon.</param> /// <returns>A System.Drawing.Icon object of the program associated with the given file.</returns> public static Icon GetFileIcon(string iFile, bool iGetLarge) { if (!File.Exists(iFile)) { return null; } SHFILEINFO fileInfo = new SHFILEINFO(); if (! iGetLarge) { SHGetFileInfo(iFile, 0, ref fileInfo, (uint)Marshal.SizeOf(fileInfo), 0x100 | ICON_SMALL); } else { SHGetFileInfo(iFile, 0, ref fileInfo, (uint)Marshal.SizeOf(fileInfo), 0x100 | ICON_LARGE); } return Icon.FromHandle(fileInfo.hIcon); }It sounds like you're looking at an easing function which creates a smoother transition or movement than a linear change over time. If you use a box moving from one place to another as an example, one type of easing would be to start out fast but slow down as it moves into place instead of having it abruptly stop. A google search for easing functions will find tons.
I guess that makes sense, and would apply to other such situations as well, thanks! I was asking mostly because I was curious.
There's also a way to do it for classes, you just do it from the other end.
Now, I'm not familiar enough with C++/CLI to actually show you some code, but what you'd basically do is take an instance of the C++ class (or struct) in question, wrap it up inside a C++/CLI managed class, compile to an assembly, add to your project, and bam, you've got it.
I came up with a working solution.
*****EDIT*****
I am using perl to do some data manipulation on some text files. The files have roughly this format.
[Section 1] { ***Lines of data*** } [Section 2] { ***Different Lines of data*** } etc.....The formatting is as above with the specific brackets in the locations shown. Each section of data will have to be edited slightly differently than the others. I want to know a good way for the code to read the file and know what section it is in so that the appropriate changes can be made. Perl does a great job of mindlessly going through a file and changing each line without knowing (or caring) where it is. I just want to know how to make it aware of its location. I can handle everything else, I just need to know how to plot the logic for this out first.
Thanks for your help.
*****EDIT******
Nevermind, I came up with a working solution.
I have 549 Rock Band Drum and 305 Pro Drum FC's
REFS REFS REFS REFS REFS REFS REFS REFS
for work, i manage drawing files for several projects
we get several hundred for each project, and each drawing for each project will go through several revisions.
each drawing is a seperate pdf
the naming convention goes something like xy-4502_rb where rb is the revision number, and goes from a-some letter, then from 0-inifinty. There are often times i'd like to move/copy these files automatically if the drawing has been superceeded (rb and rc exist in the same directory, i would want to copy rb to my superceedeed folder) and i'd also lke to maniupulate the drawing name so that STAMPED xy-4505_rb would be xy-4505_rb STAMPED so that they organize nicer. Can anyone point me in the right direction?
Check the docs for os.path and file/directory manipulation.
will i need to run these thingy's in python, or is creating a windows executable even close to an option?
You'll need to install Python to develop it, but you can use distutils and py2exe to create a Win32 executable of the finished script.
EDIT: if this is some sort of corporate thing, or if you plan to write more scripts in the future, I advise just installing Python on all the computers that will run them.
py2exe plus a good nsis script will be able to create a one click exe that will self contain everything it needs, so no need for install.
python should have no problem doing this, since you basically are just asking to use os.walk, and some os.path commands. The only thing I would watch out for is some of the path commands expect unix slashes only so you might have to do some preprocessing.
Cue my entrance.
I had to take a few years off from my programing exploits of some minor web stuff (Flash, mostly), a smidge of Java and C#, and today I would like to start my quest on learning Python, as it seems to be damn near the most handy thing in the world.
Anyone care to point me in the way of a good IDE and maybe some tutorials?
The only IDE I can find is pydev for Eclipse, which is kind of a pain in the ass to set up but seems to work. Every time I click "run" it prompts me for a VM though, which is fucking annoying.
I haven't found a Windows plain text editor that I like. Notepad++ has great code hilighting & stuff, but it only manages documents in a horizontal tab bar, which is fucking retarded if you have a project of any size at all. TextPad is not free, and has shitty unantialiased text rendering, making me wonder why you would pay for it.
TextMate and TextWrangler are the only OS X solutions of any merit that I can find.
As for tutorials, I've been working from a combination of the free "Dive Into Python" book and the official documentation (which has a tutorial section somewhere with a nice TOC featuring all the basics).
so i'm having a hard time understanding what they mean by "path" and stuff like that.
What specifically are you having problems with? That might help. The path that he's talking about is the location of a file or directory.
In linux it would look like: /home/user/Documents
In Windows: C:\Programming\Project
Like Ethea said some commands are expecting the linux type slashes, if you have problems anywhere look into that.
So, these fancy new spriteFonts are fine and dandy, but I want to do something... unorthadox with them
I need to somehow let the user enter a string, then create a 2d array with width (in pixels) that that string would become when run through the spritefont dealy, and height being the height of the highest letter. Then I need to fill this array with a 1 wherever the image is black and a 0 wherever it's white.
So, for example, the word LOL
Would end up (roughly, using a small blocky font) in the array as
100010010
100101010
100101010
110010011
This array will then become that font, but in 3d little cubes.
Any help deserves mad props. Thanks.
For example, if you wanted to list all the files and directories in C:\, you'd execute "os.listdir ('C:\\')". Double backslashes are required for Windows-style paths. It is possible to use raw strings for that, but I advise against it because some of their behavior is not obvious when used for paths. For example, a raw string cannot end with a single backslash.
Well with a combination of System.Text and System.Drawing you can create Bitmaps from text input.
Then you could take the resultant bitmap and analyze each bit for it's color and then create a matrix or what have you of 0's and 1's.
But that array would gigantic (one entry per pixel) so you'd have to think of some way to shrink it down to the right size, say, for every 5 adjacent black pixels only do a single 1.
That's all I can think of on a whim.
Currently I'm messing around trying to create a simple little 2D sprite game. I've been reading some tutorials and as far as most of them get with 2D is just drawing a sprite to the screen. They then either want to jump right into making a basic physics engine or into 3D.
What I need to know is what is the best way "i.e. best practice" for taking a sprite off the screen. What I mean is, lets say I have SpriteA and lets say SpriteA is the sprite for a giant enemy crab or something. Lets also say that I hit the weak spot on SpriteA for massive damange and killed the crab. Now that the grab is dead I don't want to draw SpriteA to the screen anymore. So do I just not call the draw method or is there some kind of content unload method I should be calling?
Tofu wrote: Here be Littleboots, destroyer of threads and master of drunkposting.
Just don't draw the sprite to the screen anymore. The only thing that might need to be unloaded is the sprite data itself, but
1. It'll be unloaded when the program ends.
2. You'll probably want to keep it incase you need to use it again without having to load it again.
If you need to get rid of it before you call Content.Unload(), you can do Texture2D.Dispose(), which should release its unmanaged resources (and will cause an error if you try and draw it after that).
Good stuff, thanks.
Tofu wrote: Here be Littleboots, destroyer of threads and master of drunkposting.
On the subject of this, does C# have support for destructors?
Kinda, but from what I've read its advised that beginners not mess with them and just create a Initialize method in your class instead to be called from the Initialize method of Game1 (as far as XNA goes). But I think all constructors and destructs are just overloads of the base class of all classes or something.
EDIT: Here is a snip from the msdn:
"If the class does not have a constructor, a default parameterless constructor is automatically generated for you and the default values are used to initialize the object fields"
I believe the same is true for destructors.
Tofu wrote: Here be Littleboots, destroyer of threads and master of drunkposting.