[QUOTE=Robert64;22202121]Like before I have a dictionary of dictionaries, each containing objects extended from my RBase class. Is there an easy way to add a new object of the correct class if I have the class name as a string?
[code]resource_lists[ "R" + new_item_type ].Add( new_item_name, new /*dynamic type*/( new_item_params ));[/code]
I don't want to have to use a select case statement or anything if its possible to avoid one.[/QUOTE]
Use reflection
[cpp]
using System.Reflection;
RBase var = (RBase)Assembly.GetExecutingAssembly()
.GetType("RWhatever")
.GetConstructor(new Type[] { /* parameter TYPES */ })
.Invoke(new object[] { /* actual parameter objects */ });
[/cpp]
Ok, I'm getting somewhere (I hope)
I'm trying to save the items in a Listbox to a .txt file in the path "Setting/list.txt".
When I click the button, whatever is in the textbox is added to the table. (This works) but I want it to also save it to the table. There is also a button to remove items from the table (This works) But I also want it to remove it from the .txt file. I don't know how to do this and I can't really find any good help.
Code for the "Add shit to Listbox" button:
[code]
If TextBox1.Text = "" Then
'Do nothing
Else
ListBox1.Items.Add(TextBox1.Text.ToString())
End If
[/code]
Code for the "Delete shit from the listbox" button:
[code]
ListBox1.Items.Remove(ListBox1.SelectedItem)
[/code]
So far I'm able to load objects from a .txt file into the form (That's good I think)
[code]
Private Sub favorites_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Items.AddRange(Split(My.Computer.FileSystem.ReadAllText("settings/favorites.txt"), vbNewLine))
End Sub
[/code]
Can someone help? [I]Yes, it's Visual Basic. Whenever I start a project I make the first "Draft" in VB.[/I]
I have a class at school written in VB to do exactly that.
[QUOTE=Chad Mobile;22205928]Ok, I'm getting somewhere (I hope)
I'm trying to save the items in a Listbox to a .txt file in the path "Setting/list.txt".
When I click the button, whatever is in the textbox is added to the table. (This works) but I want it to also save it to the table. There is also a button to remove items from the table (This works) But I also want it to remove it from the .txt file. I don't know how to do this and I can't really find any good help.
Code for the "Add shit to Listbox" button:
[code]
'Code
[/code]
Can someone help? [I]Yes, it's Visual Basic. Whenever I start a project I make the first "Draft" in VB.[/I][/QUOTE]
I'm not sure about VB, but you could write a class that on Adding/Removing an item also deletes the text file and replaces it with whatever's in the list.
Okay, i'm trying to write a 2D top-down RPG game in VB.NET and i've been doing pretty well so far. I'm now trying to make my code a bit easier to work with by allowing it to read a .lvl file (it's plain text, written in notepad) that tells my game what map to load, what tileset to use, where to place what NPC's etc...
The code is in different classes to try and keep things cleaner. I have the code to read the .lvl file in a class, and I have another class to load sprites, another one to load my maps and so on. I then also have a class which "holds it all togeather" if you like. In this class, I have the lines:
[code]Public Shared Level As New clsLevel()
Public Shared map As clsMap
[/code]
The clsLevel class is what tells my map class what to load, and the clsMap class actually renders the map. In my clsLevel class, once it has read the file I give it, it SHOULD be using the following line to pass information to my clsMap class:
[code]GameClass.map = New clsMap(map, tileset)[/code]
(map and tileset are both strings taken from the .lvl file it reads)
However when I run this I get an "Object reference not set to an instance of an object" error. I'm guessing that's because I declare 'map' as clsMap, rather than 'New clsMap'. But when I do that I have to give it the information about which tileset and map file to use, rather than having it taken from my .lvl file. My clsLevel class is declaring it as a 'New clsMap' - So I don't see why that isn't working properly.
If anyone can help me it would be massively appreciated!
[QUOTE=turb_;22203652]Use reflection
[cpp]
using System.Reflection;
RBase var = (RBase)Assembly.GetExecutingAssembly()
.GetType("RWhatever")
.GetConstructor(new Type[] { /* parameter TYPES */ })
.Invoke(new object[] { /* actual parameter objects */ });
[/cpp][/QUOTE]
Thanks :3:
[editline]05:42PM[/editline]
I get a NullReferenceException on that line, I probably added it incorectly:
[code]RBase new_item = ( RBase ) Assembly.GetExecutingAssembly()
.GetType( new_item_name )
.GetConstructor( new Type[] { this_obj.GetType() } )
.Invoke( new object[] { this_obj } );[/code]
Am I going crazy or what, :
[cpp]
float heightDisplacement = (maxRarity - minRarity) / (height - empty - 1);
[/cpp]
it says in debugging mode that
maxRarity - minRarity = 99
and (height - empty - 1) = 192
and heightDisplacement stays 0.
[QUOTE=quincy18;22216512]Am I going crazy or what, :
[cpp]
float heightDisplacement = (maxRarity - minRarity) / (height - empty - 1);
[/cpp]
it says in debugging mode that
maxRarity - minRarity = 99
and (height - empty - 1) = 192
and heightDisplacement stays 0.[/QUOTE]
Make sure that it isn't doing integer division which will round down. Cast the two sides of the division as (float)s and see if that fixes it.
[QUOTE=Robert64;22216535]Make sure that it isn't doing integer division which will round down. Cast the two sides of the division as (float)s and see if that fixes it.[/QUOTE]
Yes it did thanks, stupid I didn't see that.
[QUOTE=Robert64;22215507]I get a NullReferenceException on that line, I probably added it incorectly:
[code]RBase new_item = ( RBase ) Assembly.GetExecutingAssembly()
.GetType( new_item_name )
.GetConstructor( new Type[] { this_obj.GetType() } )
.Invoke( new object[] { this_obj } );[/code][/QUOTE]
The problem is that this:
[code]Assembly.GetExecutingAssembly().GetType( new_item_name )[/code]
...is returning null for some reason :(
I'm having some trouble with the 21 interupt. It does not seem to respond to anything I throw at it. This for example prints "n":
[cpp][bits 16]
[org 0x7C00]
; Clear screen (not sure how it works)
mov ax, 02
mov bx, 03
int 10h
; Move a default number in the hour register
mov ch, 25
; Get the current hour
mov ah, 2ch
int 21h
; Check if we received an hour
cmp ch, 25
jz nohour
; We got an hour, print a message to confirm this
mov ah, 0eh
mov al, "y"
int 10h
jmp $
nohour:
; We did not get an hour, print a message to confirm this
mov ah, 0eh
mov al, "n"
int 10h
jmp $
; Fill remaining bytes, because a bootloader has to be exactly 512 bytes
times 510 - ($ - $$) db 0
; Boot footprint
dw 0xAA55[/cpp]
[url=http://ip-tietgennet.tietgen.dk/staff/mlha/PC/Prog/asm/int/21/index.htm#2C][u]This[/u][/url] is the reference I used.
[QUOTE=Robert64;22217875]The problem is that this:
[code]Assembly.GetExecutingAssembly().GetType( new_item_name )[/code]
...is returning null for some reason :([/QUOTE]
Disregard that I suck cocks
[editline]09:23PM[/editline]
not the best post to be page king
Can we stop with the "OMG ME NO DESERVE PAGEKING"
@Overv: I don't think that will work. INT 21 is a DOS API interrupt, and you're trying to use it in a bootloader. I think you'll have to use INT 1A.
[url]http://montcs.bloomu.edu/Information/RTC.x86.from-jabberwocky/RTC.x86/BIOS.RTC/int-0x1a.RBIL.html[/url]
[url]http://www.sat.dundee.ac.uk/~psc/dosemu_time_advanced.html[/url]
Here is a list of BIOS interrupts. Any other interrupts are probably not usable from a bootloader.
[url]http://en.wikipedia.org/wiki/BIOS_interrupt_call[/url]
[QUOTE=Jawalt;22219618]Can we stop with the "OMG ME NO DESERVE PAGEKING"[/QUOTE]
No one complained about people doing it, so I did it and... :saddowns:
-snip- solved it myself
What I'm making is a C++ RPG Choose-your-own-adventure type game. I want to have branching paths, but I don't want to put them in different functions. How do I do this?
@Robert64 I think you need to include the namespace as well
as the class name. I didn't check the code before posting, sorry.
[QUOTE=turb_;22223086]@Robert64 I think you need to include the namespace as well
as the class name. I didn't check the code before posting, sorry.[/QUOTE]
I worked it out after a while, but thanks for all the other help you gave :smile:
I just got OGRE working with VC++ Express 2010, and it compiles, but after I choose the renderer I just get a black screen. Anyone know anything about this?
[editline]11:59PM[/editline]
Ohwow I'm dumb. Just a template not a tutorial. Misleading names.
~snip
Yeah that looks pretty sweet (except for the part on Intellectual Property Rights)
[QUOTE=shill le 2nd;22228640]Yeah that looks pretty sweet (except for the part on Intellectual Property Rights)[/QUOTE]
Alright, thanks. Now I just need to find out how to sign up for it since school is out and usually you need your counselor to check it out.
I have an RP-ish thing going, that I want to have multiple paths.
[code]
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
string name;
string reply;
char strnew[255];
// The sections
int s1();
int s1torch();
int s1zombie();
int s1pit();
int s2();
int s3();
//Greeting
int main()
{
cout << "Greetings! Welcome to the Turnip Role Playing Game! \n I am the Dungeon Master! Let's begin! \n What is your first name? \n";
cin >> name;
system("cls");
cout << "Okay, " << name << ", let's get down to buisness! \n PRESS ENTER TO CONTINUE";
s1();
}
// First part of the adventure
int s1()
{
cout << "You awake in a dark area. The drip of water fills echos throughout the space. Your choices to move are NORTH, SOUTH, or WEST.\n <ANSWER IN ALL CAPS, ONE WORD>";
cin >> reply;
strncpy(strnew,reply,1);
switch(strnew)
{
case "NORTH":
s1torch();
break;
case "SOUTH":
s1zombie();
break;
case "WEST":
s1pit();
break;
default:
cout << "Unable to " << reply <<".";
}
}
int s1torch()
{
}
int s1zombie()
{
}
int s1pit()
{
}
[/code]
And the switch function apparently doesn't accept switch() functions. Help?
You can't switch on strings in C++. Use else-if instead (barring the use of more a scalable method).
How can I read pixels from a window in OpenGL?
[QUOTE=Dacheet;22231699]
And the switch function apparently doesn't accept switch() functions. Help?[/QUOTE]
Why you are using this?
[code]strncpy(strnew,reply,1);[/code]
[editline]05:35PM[/editline]
[QUOTE=jA_cOp;22232845]You can't switch on strings in C++. Use else-if instead (barring the use of more a scalable method).[/QUOTE]
And by "more scalable method", do you mean std::map and enum?
[code]#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
typedef map<string, int> stringMap_t;
stringMap_t mapDirs;
enum {
NORTH,
SOUTH,
WEST
};
mapDirs.insert(stringMap_t::value_type("NORTH", NORTH));
mapDirs.insert(stringMap_t::value_type("SOUTH", SOUTH));
mapDirs.insert(stringMap_t::value_type("WEST", WEST));
string reply;
cout << "You awake in a dark area. The drip of water fills echos throughout the space. Your choices to move are NORTH, SOUTH, or WEST.\n <ANSWER IN ALL CAPS, ONE WORD>";
cin >> reply;
switch(mapDirs.find(reply)->second) {
case NORTH:
cout << "NORTH!" << endl;
break;
case SOUTH:
cout << "SOUTH!" << endl;
break;
case WEST:
cout << "WEST!" << endl;
break;
default:
cout << "NONE!" << endl;
}
return 0;
}
[/code]
[QUOTE=Darwin226;22241317]How can I read pixels from a window in OpenGL?[/QUOTE]
Use [url=http://www.opengl.org/sdk/docs/man/xhtml/glReadPixels.xml]glReadPixels[/url] with a width and height of 1, 1.
Thank you very much.
[QUOTE=Darwin226;22241317]How can I read pixels from a window in OpenGL?[/QUOTE]
It's going to be really slow just an FYI.
OK, so I gots three separate forms. "Form1", "Form2", and "Form3" (:v:)
"Form1" is the main form, and "Form2" and "Form3" are the "minor" forms. They are like little menus for "Form1". They don't appear in the task bar. How can I make it so if they are accidentally covered by "Form1" then they are closed?
Sorry, you need to Log In to post a reply to this thread.