Boolean not passing

Started by technik3k, September 04, 2015, 01:03:53

Previous topic - Next topic

technik3k

the invoke sends info to the main:

public void invoke(long window, int key, int scancode, int action, int mods) 
		{
			Keyboard[key] = action != GLFW_RELEASE;
			
			test.ReciveKeyboard(Keyboard);
		}


this is the reciving function:

public static void ReciveKeyboard(boolean KeyboardR[]) 
	{
		KeyboardR = Keyboard;
	}


The Reciving function seems to not work(Data not being recived) ???

abcdef

There isn't really much to go on here, what in your post actually works? For the bits that don't work be a bit more explicit in explaining what is not working, ie what is expected to happen and what isn't.

quew8

That would be because your receive function does absolutely nothing. You reassign a reference "KeyboardR" local to that function. As soon as the function ends, "KeyboardR" (the reference) gets garbage collected and your function has done a sum total of nothing.

I presume what you meant to do is
Keyboard = KeyboardR;


I'll explain briefly. Java is a pass by value language but it stores everything as a reference. So when you call a function with a parameter, it passes the value of a the reference to that parameter. Lets assume you have passed an array. Now if you access an element of that array in the function, it will access an element of the original array. If you set an element of that array in the function, it will set an element of the original array. However if you reassign the array in the function, all you are doing is reassigning the reference to the array to reference a different array.

Even this however will probably not do what you want it to but since I don't know what you are trying to do I won't correct you.

technik3k

Thank you. :) It's just that silly thing that you always miss. ;)