Tomb Raider - code help - what are functions - lua default code for level

on level/deja-brew I use

self:say("Take", numToTakeDown + " down, pass it around!")

on the watch screen it shows the hero singing with the rest perfectly just like he should but I get a syntax error from this line and I don’t pass the level

nvm just removed the function and said 1 like you should tho it seemed like it should have worked at least I was positive I seen my hero singing along now thought after reset he dont when using said code.

Nice explanation of what () do
but he eventually comes to pets
To Event handlers
and for sure will be confused
Why no () in this case

So if we look at this line of code closely how is it similar or different from the one given? hero:say(potionsOnTheWall + " potions of health on the wall!")

And do you know what the difference is between:

someFunction( “one” + “two” + “three” )

and

someFunction( “one” , “two” , “three” )

?

ok duh I need to use + instead of , but what dose , do?

it worked in

pet:say("hear", speak)

for that matter what dose “hear” do? Because the pet don’t actually say hear.

@LordMaddog if we have the following function:

local someFunction = function( firstArgument, secondArgument, thirdArgument )
    if firstArgument then
        hero:say( firstArgument )
    else
        hero:say("There is no first argument")
    end

    if secondArgument then
        hero:say( secondArgument )
    else
        hero:say("There is no second argument")
    end

    if thirdArgument then
        hero:say( thirdArgument )
    else
        hero:say("There is no third argument")
    end        
end

What will the following pieces of code do?

someFunction( “one” + “two” + “three” )

someFunction( “one” , “two” , “three” )

I believe you mean

pet:on("hear", speak)

The pet.on() function is predefined as well. It takes 2 arguments. the first being an indicator about what action took place and the second is the actual name of a function to execute when this occurs.

It is like saying in English:

Pet, when you “hear” something perform the “speak” functions action.

The list of actions that can be used to trigger this to happen are limited by a predefined list. "hear" was chosen for when characters in the game speak.

1 Like

I see I din’t know you could define a word in " to be a function tho.

so from what I am seeing , dictates target (either function or .id) and + is add.

Is that correct?

@LordMaddog perhaps this illustration will help?

The commas separate things that you send to a function. So for instance if we use our previous example of the function that cleanAndScrub()'s dishes this is one way we could send many dishes to be cleaned:

local dish1 = "A dirty Dish"
local dish2 = "A grimy Dish"
local dish3 = "A filthy Dish"
cleanAndScrub( dish1, dish2, dish3 )

remember that this is just an example and the “dishes” we are talking about are really just strings.

in the pet example we are sending two things to the function on(). A string "hear" and the name of a function speak.

speak would need to be defined in your code:

local speak = function()
    pet:say(" I am talking ")
end

And if you are asking why are we using the word argument for programming and wondering why we should be fighting with our functions and not having a constructive discussion here is a nice read:
1 Like

Thank you.

I am learning a lot and I really like you game its amazing!

You are welcome. And I enjoy their game as well. I am just a community member like yourself.

@LordMaddog if it is alright with you, I am going to update the title of your post to help the rest of the community who might have similar questions.

How so ? I mean can you clarify with an example.

i simply remember how i was confused
then encountered this
why handler is

pet.on( "hear", function )

instead

pet.on( "hear", function() )
@LordMaddog if it is alright with you, I am going to update the title of your post to help the rest of the community who might have similar questions.

sure

also for pets level/go-fetch onward the instructions are in Java not Lua.

So in this case if we think of

function as a noun

and

function() as a verb

Then we can observe that we are sending the actual function as an argument into the pet.on() function and not the result of running the function() right? If we used the function as a verb and ran it, we would be telling the code to take the return value and send that as the argument instead of the function itself.

There is no reason why we couldn’t use a function() that returns a function and put that into the second argument spot right? Unless the programming language disallows calling a function within an argument space.

-HW

2 Likes

O wow that example is phenomenal!

It makes every thing so clear

once again thank you.

Posted LUA conversions

Updated:

  • Go Fetch
  • Buddy’s Name
  • Phd Kitty
  • Pet Quiz
  • Guard Dog
  • Long Road
  • Forest Jogging
  • Forest Cannon Dancing

Adding more patches here:

How about pet quiz? I’m having problems on that. Especially defining petSay thing.:sweat:

I am working on level 28 tomb raider and my code won’t work for some reason, here it is can somone help?
define function checkToDefend(target)
target equals hero:findNearestEnemy()
if target then
hero:attack(target)
on this line I have a syntax error that keeps poping up and saying that there is a problem with my code.

Many reasons for it could exist. Giving some screenshots may help)
Maybe lack of proper equipment (such as glasses f.e.)