Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Are some values in parameters already defined?

Ok, so I understand functions, but I don't understand the parameter part when you put:

local function onInputChanged(input, gameProcessed) 
if input.UserInputType = Enum.UserInputType.MouseMovement then
print("The mouse has been moved!")
		printMovement(input)
end

Yes, isn't input and gameProcessed not defined?
Why do you put On when you do that?
Why doesn't this script work, but worked before when I used it
How come some values in parameters have a value while others do not.

local function PlayerAdded(player)  

Isn't player not defined?
Some part in there, you put

player.Character

How can you define the character of the player in the parameter if the value of the player is not defined?
it's just in the function PlayerAdded()
Relatively, the same thing for local function(input, GameProccessed)
Is Gameprocessed or input even defined does it have a value at all?
How then does it work the script

game:GetService("UserInputService").InputBegan:connect(function(Action1)
if Enum.KeyCode.R then
print("R  was pressed")
end

local function onInputChanged(input,gameProcessed)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		print("The mouse has been moved!")
		printMovement(input)
	elseif input.UserInputType == Enum.UserInputType.MouseWheel then
		print("The mouse wheel has been scrolled!")
		print("\tWheel Movement:",input.Position.Z)
	elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
		if input.KeyCode == Enum.KeyCode.Thumbstick1 then
			print("The left thumbstick has been moved!")
			printMovement(input)
		elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then
			print("The right thumbstick has been moved!")
			printMovement(input)
		elseif input.KeyCode == Enum.KeyCode.ButtonL2 then
			print("The pressure being applied to the left trigger has changed!")
			print("\tPressure:",input.Position.Z)
		elseif input.KeyCode == Enum.KeyCode.ButtonR2 then
			print("The pressure being applied to the right trigger has changed!")
			print("\tPressure:",input.Position.Z)
		end
	elseif input.UserInputType == Enum.UserInputType.Touch then
		print("The user's finger is moving on the screen!")
		printMovement(input)
	elseif input.UserInputType == Enum.UserInputType.Gyro then
		local rotInput,rotCFrame = UserInputService:GetDeviceRotation()
		local rotX,rotY,rotZ = rotCFrame:toEulerAnglesXYZ()
		local rot = Vector3.new(math.deg(rotX),math.deg(rotY),math.deg(rotZ))
		print("The rotation of the user's mobile device has been changed!")
		print("\tPosition",rotCFrame.p)
		print("\tRotation:",rot)
	elseif input.UserInputType == Enum.UserInputType.Accelerometer then
		print("The acceleration of the user's mobile device has been changed!")
		printMovement(input)
	end	
end
 
UserInputService.InputChanged:connect(onInputChanged)

2 comments

0

Just a tip for next time: be mindful of the syntax highlighter for code blocks, and other markdown options. It helps organize your question, and in doing so, helps the people reading it.

0

Edited for formatting.

1 answer

When you say function foo(arg) that defines the name of the first argument to be arg.

The value of arg is then the first argument where foo is called.

For example,

function talkabout(something)
	-- `something` is the name we give to the first "argument" to `talkabout`
	print("I'm talking about " .. something)
end

talkabout(17)
--> I'm talking about 17

In the above example, something got the value of 17 since that's the argument that was passed to talkabout.

It is up to the caller of the function to provide the correct parameters.

Note that the name given in the definition doesn't matter outside the function. This code is not distinguishable from the above:

function talkabout(topic)
	print("I'm taling about " .. topic)
end

Event handlers

All of the functions you mentioned are used as event handlers.

These functions are called automatically by events.

If you read the Wiki article for the event, you will see with what arguments the function is called.

For example, for PlayerAdded,

Parameters: player (of type Player)

This tells you that the first and only argument to the function that handles a PlayerAdded event is a player object (you can infer that it's the player that just joined).

If you look at InputChanged you see the parameters are

Parameters: input (of type InputObject), gameProcessedEvent (of type bool)

This tells you the first thing your function will receive is an InputObject, and the second thing is a boolean.

The precise meaning of those parameters is described further in the documentation on the wiki page.

This discussion is preserved as it was. New answers, comments, and votes are closed.