[QUOTE=frdrckk;46709733]How do I pass-by-reference/pointer a character array so that I can modify it's contents on another function? It's been doing my head in.[/QUOTE]
[cpp]void f(char* const str)
{
str[0] = 'a';
}[/cpp]
Straight forward, what exactly do you have a problem with?
[QUOTE=Dienes;46709756][cpp]void f(char* const str)
{
str[0] = 'a';
}[/cpp]
Straight forward, what exactly do you have a problem with?[/QUOTE]
So I call the function
[code]shop(&level, &money, &bait, &rod, ...);[/code]
and the function has parameters
[code]void shop(int *level, int *money, int *bait, ...)[/code]
and it gives me this error
[code]Error error C2664: 'shop' : cannot convert parameter 4 from 'char (*)[25]' to 'char *[]'[/code]
sorry if it seems trivial
[QUOTE=frdrckk;46709795]So I call the function
[code]shop(&level, &money, &bait, &rod, ...);[/code]
and the function has parameters
[code]void shop(int *level, int *money, int *bait, ...)[/code]
and it gives me this error
[code]Error error C2664: 'shop' : cannot convert parameter 4 from 'char (*)[25]' to 'char *[]'[/code]
sorry if it seems trivial[/QUOTE]
Not sure where those ints are coming from (probably you meant to write char), but just call it without the address-of operator:[cpp]void f(char* const str)
{
str[0] = 'a';
}
int main()
{
char str[] = "test";
f(str);
}[/cpp]
[QUOTE=Dienes;46709800]Not sure where those ints are coming from (probably you meant to write char), but just call it without the address-of operator:[cpp]void f(char* const str)
{
str[0] = 'a';
}
int main()
{
char str[] = "test";
f(str);
}[/cpp][/QUOTE]
Okay, doing that seems to fix it now. Thanks
Also, I'm passing multiple integer values into the function as well because those need to be modified too.
I'm trying to serialize a list of followers in Ruby to JSON. I'm brand new to JSON, but here's what I've got
My Follower:
[CODE]require 'json'
class Follower
attr_accessor :name, :handle, :bio
def initialize(name, handle, bio)
@name = name
@handle = handle
@bio = bio
end
def to_s
"#{@name}\n#{@handle}\n#{@bio}"
end
def to_json(*a)
{
'json_class' => self.class.name,
'data' => ["name" =>@name,"handle"=>@handle,"bio" =>@bio]
}.to_json(*a)
end
def self.json_create(o)
self.new(o['data'])
end
end
[/CODE]
my test
[CODE]require 'json'
require './Follower.rb'
follower = Follower.new("somedude", "@somedude", "lol")
string = follower.to_json
puts string #works just fine
follower.json_create(string)
p follower
[/CODE]
But I get "JSONTest.rb:9:in `<main>': undefined method `json_create' for #<Follower:0x00000001cdbaa8> (NoMethodError)"
-snip- I am dumb.
I mostly feel absolutely retarded when attempting to write applications and software (although I do like doing it), but this one really had me going. I was working with some simple OpenGL shit just for the hell of it, but then
[code]
fish: Job 1, “../build/src/pong ” terminated by signal SIGSEGV (Address boundary error)
[/code]
Oh, well that's no fun. It seems the error was in glShaderSource for some reason? Well, maybe I did something wrong when loading the shader file:
[code]
int f_vert = open( "vert.vert", 'r' );
size_t vert_size = lseek( f_vert, 0, SEEK_END );
lseek( f_vert, 0, SEEK_SET );
char *vert = malloc( vert_size );
read( f_vert, vert, vert_size );
close( f_vert );
[/code]
While not pretty, it should probably work.
Lets have a look again:
[code]
int f_vert = open( "vert.vert", 'r' );
size_t vert_size = lseek( f_vert, 0, SEEK_END );
lseek( f_vert, 0, SEEK_SET );
char *vert = malloc( vert_size );
read( f_vert, vert, vert_size );
close( f_vert );
GLuint vertexShader = glCreateShader( GL_VERTEX_SHADER );
glShaderSource( vertexShader, 1, vert , NULL );// <- major shitstorm here
[/code]
Alright, fuck it, lets just
[code]
glShaderSource( vertexShader, 1, "#version 330\n\nvoid main() { }\n", NULL );
[/code]
STILL failing? Alright, I'm done. Anyone got any ideas?
[editline]14th December 2014[/editline]
Alright, nevermind, turns out I forgot to do
[code]
glShaderSource( vertexShader, 1, &vert , NULL );// <- major shitstorm fixed
[/code]
instead of
[code]
glShaderSource( vertexShader, 1, vert , NULL );// <- major shitstorm here
[/code]
Must've been staring myself blind on the issue. Sorry.
[QUOTE=blacksam;46711329]I'm trying to serialize a list of followers in Ruby to JSON. I'm brand new to JSON, but here's what I've got
My Follower:
[CODE]require 'json'
class Follower
attr_accessor :name, :handle, :bio
def initialize(name, handle, bio)
@name = name
@handle = handle
@bio = bio
end
def to_s
"#{@name}\n#{@handle}\n#{@bio}"
end
def to_json(*a)
{
'json_class' => self.class.name,
'data' => ["name" =>@name,"handle"=>@handle,"bio" =>@bio]
}.to_json(*a)
end
def self.json_create(o)
self.new(o['data'])
end
end
[/CODE]
my test
[CODE]require 'json'
require './Follower.rb'
follower = Follower.new("somedude", "@somedude", "lol")
string = follower.to_json
puts string #works just fine
follower.json_create(string)
p follower
[/CODE]
But I get "JSONTest.rb:9:in `<main>': undefined method `json_create' for #<Follower:0x00000001cdbaa8> (NoMethodError)"[/QUOTE]
json_create is a class method, but you're calling it on an instance.
Me and my friend have been stuck with ghost vertice problem in our 2D game for a while. So far we've tried rounding the player collision box corners, changing the bottom to a circle to smooth the movement, thought the problem still occurs (the player bounces when moving once he hits tile edges). We are using JBox2D to move our character.
Our current collision thingies (white lines represent collision boxes):
[img_thumb]https://dl.dropboxusercontent.com/u/38084031/stuffff.png[/img_thumb]
This is how we move the player:
[code]
if (input.isKeyDown(Input.KEY_RIGHT)) {
p.setState(2); // Set current animation to MOVE right.
p.setStateAfter(0); // Set player IDLE to face right.
body.m_linearVelocity.x = 2; // Do the moving.
}[/code]
[QUOTE=Edvinas;46716349]Me and my friend have been stuck with ghost vertice problem in our 2D game for a while. So far we've tried rounding the player collision box corners, changing the bottom to a circle to smooth the movement, thought the problem still occurs (the player bounces when moving once he hits tile edges). We are using JBox2D to move our character.
Our current collision thingies (white lines represent collision boxes):
[img_thumb]https://dl.dropboxusercontent.com/u/38084031/stuffff.png[/img_thumb]
This is how we move the player:
[code]
if (input.isKeyDown(Input.KEY_RIGHT)) {
p.setState(2); // Set current animation to MOVE right.
p.setStateAfter(0); // Set player IDLE to face right.
body.m_linearVelocity.x = 2; // Do the moving.
}[/code][/QUOTE]
You could always group the tiles that lie in a line into a single mesh.
We were considering that idea, but we want to be able to remove/place tiles real-time like in Terraria for example, can't quite wrap our heads around how to implement that. For example if we remove a tile in a xy place, how do we check which meshes should be regenerated instead of the whole map.
[QUOTE=Edvinas;46716494]We were considering that idea, but we want to be able to remove/place tiles real-time like in Terraria for example, can't quite wrap our heads around how to implement that. For example if we remove a tile in a xy place, how do we check which meshes should be regenerated instead of the whole map.[/QUOTE]
Disclamer: Haven't done this myself and haven't put a lot of thought into it.
Each mesh consists of at least one tile. Make a table that for every tile gives you the mesh that contains it. Then, when you add or remove the tile, you just need to check if the meshes in 4 directions around the tile you modified need changing.
The way you generate is something like:
-Have one mesh per tile
-Push into a set all the outer tiles (the ones player can touch)
-For each tile in the set, check if it can be a part of a horizontal or a vertical line mesh (there are few possible cases you'll need to check)
-Expand in that direction merging with meshes as you go and removing those meshes from the set.
After you empty out the set, all the border tiles should have nice long meshes. When you modify stuff, just regenerate the meshes that the modified tile touches.
[QUOTE=Jitterz;46668942]I am probably way in over my head, as I said earlier, I thought it wasn't going to be too complicated. I found that DataSet has a WriteXml() method. That is currently what I am pursuing.[/QUOTE]
I've just had to work this out myself. DataSet happens to extend IXmlSerializable so it implements ReadXml() and WriteXml(). Those are the methods the XmlSerializer will call if your class implements IXmlSerializable, and you can use them to control how and what the XmlSerializer does.
I learned how to implement IXmlSerializable in order to serialize my classes the way I wanted to. The MSDN documentation for this interface is horrible. The XmlSerializer itself is also pretty terrible. It cannot automatically serialize a class that implements IDictionary, for example. It only knows how to automatically serialize the primitive types, and IEnumerables of primitive types.
Here's a [url=http://www.codeproject.com/Articles/141955/Both-XML-and-Binary-Serializable-Dictionary]codeplex article[/url] that implements a SerializableDictionary by extending IXmlSerializable. I found it to be extremely helpful understanding how to use the basic XmlSerializer class.
One minor point: using AssemblyQualifiedName property may cause the runtime to execute the C# Compiler during deserialization. It's kludgy as f**k. Also, the compiler may not be available where your code is executing. To avoid this, do not use the AssemblyQualifiedName unless you know you have to. Use the FullName property instead, and the runtime will only try to resolve the type in mscorlib and the executing assembly. For most situations, that's all you need. The extra work of thrashing about in the GAC is a waste.
There's a more capable XML serializer available in the DataContractsSerializer class. It uses attributes to indicate how each class member is to be serialized and deserialized and handles a lot more .Net classes automatically than the XmlSerializer.
System.Object
System.Runtime.Serialization.XmlObjectSerializer
System.Runtime.Serialization.DataContractSerializer
[url]http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer(v=vs.110).aspx[/url]
C++ in visual studio for microsoft windows
I have two classes, 1 and 2, in their defenition, they both have references to eachother, as in class 1 has a reference to class 2 and class 2 has a reference to class 1, the compiler really really does not like this and gives me about 60+ error messages about things being redefined.
I need urgent help with this
[t]http://i.imgur.com/qvq8odY.png[/t]
The second I remove one of the references, the error messages all go away
That sounds like pretty bad design.
Maybe try using UML to work out some sort of design for your current code, then redesign it if you need to.
Can I ask why the classes have references to each other?
[QUOTE=Clandestina;46719384]xml craziness[/quote]
You are just overcomplicating things, reading/writing xml in C# is super easy.
[url]http://support.microsoft.com/kb/815813[/url]
Well, it's to determine who gets hit by what. The collider class contains the entity class so that it can tell whatever it collides with that it is owned by what entity and therefore can be used to determine if the entity will take damage or not. And the entity class contains the collider so it can move it around on the screen.
-snip-
Which is the norm/preferred here?
if(i = 0; i < 10; i++)
or
if(i = 1; i <= 10; i++)
The first. Unless indexes start in 1, like lua. But it would just be <
[editline]16th December 2014[/editline]
wait, if?
Oh shit, I meant for. Cheers for clarifying!
[QUOTE=Fatfatfatty;46725180]C++ in visual studio for microsoft windows
I have two classes, 1 and 2, in their defenition, they both have references to eachother, as in class 1 has a reference to class 2 and class 2 has a reference to class 1, the compiler really really does not like this and gives me about 60+ error messages about things being redefined.
I need urgent help with this
[t]http://i.imgur.com/qvq8odY.png[/t]
The second I remove one of the references, the error messages all go away[/QUOTE]
Have you forward declared one of the classes? A class has to be declared before you can use it.
[code]class B; //Forward declare class B
class A {
B& b_ref;
};
class B {
A& a_ref;
};[/code]
I'm not sure if you can use references here either. A reference cannot be left uninitialized, and I don't think there's a way to initialize both references in A and B. You probably have to use pointers instead. You can't have them be objects because that would lead to an object of infinite size (A has a B which has an A which has a B...). Also you'd need the full definition (not just a forward declare) to have an object since the compiler needs to know the size of the object.
I'm having some difficulty with flash/actionscript ExternalInterface calls from javascript. I'm trying to reverse engineer wowhead's model viewer so I can embed it on my website. I can currently embed it and I can pass it the items I want it to display on the model but I can't seem to figure out how to change the animation of the model.
I decompiled the model viewer swf and found these lines
[CODE] override public function registerExternalInterface() : void
{
ExternalInterface.addCallback("getNumAnimations",this.extGetNumAnimations);
ExternalInterface.addCallback("getAnimation",this.extGetAnimation);
ExternalInterface.addCallback("setAnimation",this.extSetAnimation);
ExternalInterface.addCallback("resetAnimation",this.extResetAnimation);
ExternalInterface.addCallback("attachList",this.extAttachList);
ExternalInterface.addCallback("clearSlots",this.extClearSlots);
ExternalInterface.addCallback("setAppearance",this.extSetAppearance);
ExternalInterface.addCallback("setFreeze",this.extSetFreeze);
ExternalInterface.addCallback("setSpinSpeed",this.extSetSpinSpeed);
ExternalInterface.addCallback("isLoaded",this.extIsLoaded);
}[/CODE]
In my html I have this (flashvars and params are defined earlier)
[CODE]swfobject.embedSWF("http://wow.zamimg.com/modelviewer/ZAMviewerfp11.swf", "mymv", "550", "400", "10.0.0", false, flashvars, params);
function test1() {
var flashobj1 = document.getElementById("mymv");
console.log(flashobj1);
console.log(flashobj1.getNumAnimations());
}[/CODE]
The console logs the flash object but trying to call getNumAnimations results in a "TypeError: undefined is not a function (evaluating 'flashobj1.getNumAnimations()')". Any idea what I may be doing wrong? How should I go about further debugging this?
[QUOTE=reevezy67;46725395]The first. Unless indexes start in 1, like lua. But it would just be <
[editline]16th December 2014[/editline]
wait, if?[/QUOTE]
it's an if-loop
[QUOTE=~ZOMG;46725393]Which is the norm/preferred here?
if(i = 0; i < 10; i++)
or
if(i = 1; i <= 10; i++)[/QUOTE]
It's not really a case of which one is the "norm" here. Both of those have different behaviours.
Here's the value of i at each iteration, for each loop, respectively:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Both have different behaviours. If you have an array arr[10], in most languages the first would work when iterating through, while the second would skip the first element and on the last iteration would cause a buffer overflow.
[QUOTE=Tommyx50;46729710]It's not really a case of which one is the "norm" here. Both of those have different behaviours.
Here's the value of i at each iteration, for each loop, respectively:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Both have different behaviours. If you have an array arr[10], in most languages the first would work when iterating through, while the second would skip the first element and on the last iteration would cause a buffer overflow.[/QUOTE]
Speaking of if loops, what is the difference between doing ++i and i++?
While I've been taught to use i++, a couple of my friends stick to ++i. They said that they were told it was faster. What is the reason for ++i being faster?
[QUOTE=HumbleTH;46729725]Speaking of if loops, what is the difference between doing ++i and i++?
While I've been taught to use i++, a couple of my friends stick to ++i. They said that they were told it was faster. What is the reason for ++i being faster?[/QUOTE]
Say you have the following code:
[code]
var x = 10
var y = 10
var a = x++ + 5;
var b = ++y + 5;
print( a )
print( b )
[/code]
The output would then be
[code]
15
16
[/code]
The reason is that i++ does assignments first, and increments post statement. Which means that x++ increments x by one AFTER the assignment, where as ++y increments y BEFORE the assignment.
[editline]17th December 2014[/editline]
I'm not aware of any speed related issues here. I do believe your friends are either wrong or trolling you.
[QUOTE=HumbleTH;46729725]Speaking of if loops, what is the difference between doing ++i and i++?
While I've been taught to use i++, a couple of my friends stick to ++i. They said that they were told it was faster. What is the reason for ++i being faster?[/QUOTE]
[QUOTE=mastersrp;46729904]I'm not aware of any speed related issues here. I do believe your friends are either wrong or trolling you.[/QUOTE]
i++ is in theory slower than ++i.
However, it's an incredibly small difference due to pipelining, and the compiler will [I]usually[/I] optimize it out anyways. The reason is because on the CPU level, doing i++ requires a copy - the code needs to be evaluated with the original value, then have 1 added to it afterwards, whereas with ++i the compiler can immediately add 1 to the value.
About the "usually" - if it's something simple like an int, the compiler can easily figure out if i++ and ++i have the same end behaviour (such as in the for loop), and optimize it away. However, if you have an object, it's a lot more vague - because of operator overloading, the compiler has no idea of the intentions of the actual function. Because of this, it's has no idea of whether the 2 are interchangeable in the circumstances.
So, essentially - if you can use either, always use ++i.
[QUOTE=Edvinas;46716349]Me and my friend have been stuck with ghost vertice problem in our 2D game for a while. So far we've tried rounding the player collision box corners, changing the bottom to a circle to smooth the movement, thought the problem still occurs (the player bounces when moving once he hits tile edges). We are using JBox2D to move our character.
Our current collision thingies (white lines represent collision boxes):
[img_thumb]https://dl.dropboxusercontent.com/u/38084031/stuffff.png[/img_thumb]
This is how we move the player:
[code]
if (input.isKeyDown(Input.KEY_RIGHT)) {
p.setState(2); // Set current animation to MOVE right.
p.setStateAfter(0); // Set player IDLE to face right.
body.m_linearVelocity.x = 2; // Do the moving.
}[/code][/QUOTE]
I had this issue a while back, the solution was to generate x/y lines from the given map. The implementation begins at the GenerateCollision() function in [URL="https://bitbucket.org/HiredK/open-mario-world/src/0286dbce15edabfe1a75e6f32394a8513cd1dfb5/src/com/hiredk/omw/engine/Sector.as?at=master"]this[/URL] file.
In VB I am trying to return the text of a label inside a cell of a gridview using this function. But it is never able to find a label, even though there is definitely one there as all my columns are templates.
[code]
Public Function ReturnLabelText(ByVal c As TableCell) As String
For Each lb In c.Controls
If lb.[GetType]() = GetType(Label) Then
Return CType(lb, Label).Text()
End If
Next
Return ""
End Function[/code]
Sorry, you need to Log In to post a reply to this thread.