Topic: Some basics.

Hey man! First of all, do you type a function like this and will it then run whatever script I have made in my function?

Ape()

Second. How do I make a script which lets say add 1 to a specific string.

Lets say I want to add 1 to HP, then do I write:

HP == HP + 1

Or how do you make that basic function?

Re: Some basics.

It depend what the function do,
or the function uses a global variable, or you pass it an argument,
for example :

function increment(x)
    return x+1
end

HP = 0

-- scene update
function onSceneUpdate()

    HP = increment(HP)

end

Re: Some basics.

I feel like I need to learn basic lua scripting first. I have learnt Lua first by using the Love2D engine, but it seems that kind of scripting doesn't apply here. Is there a good tutorial on lua scripting which apply on the Maratis engine?

Re: Some basics.

When i began utilizing this Engine, i had 0 knowledge of lua or c++ ( i still dont know C or C++) but some basics were easy to grasp by following the tutorials here:

http://forum.maratis3d.com/viewtopic.php?pid=2754#p2754

and grabbing some of the examples on the main page of Maratis3d.com and analyzing the code. hope this helps.

Re: Some basics.

Thanks, I didn't see that one about the coins. smile

Re: Some basics.

Now I have analysed all the demos, did the tutorial on youtube from part 1-9 and last but not least watched a great tutorial on lua scripting. :) Linking it here: http://www.youtube.com/watch?v=dHURyRLMOK0 and the rest continues by text on this website: http://www.dev-hq.net/lua/1--introduction-and-setup

So I figure I could write this code:

text = getObject("text")
i = 0


function increment(i)
return i + 1
end


function onSceneUpdate()
setText(text, i)
if IsKeyPressed("W") then increment() -- Calling function increment
end

I was wrong, it don't work. What am I doing wrong? :)

Re: Some basics.

Using "return" in a function means that the function return the result when you call it,
it means in your case that you have to write "if IsKeyPressed("W") then i = increment(i)"

Re: Some basics.

I'll also suggest you should not use the same name "i" for the argument and the global variable to not be confused :

text = getObject("text")
val = 0

function increment(i)
    return i + 1
end

function onSceneUpdate()
    setText(text, val)
    if IsKeyPressed("W") then
        val = increment(val) -- Calling function increment
    end
end

Re: Some basics.

Does it have to be named increment or is it just for the logic sake?

So val is automatically switched to i in the code?

I copy pasted this code but it doesn't work, I press W but it doesn't change to 1. smile

Re: Some basics.

It's not "IsKeyPressed" it's "isKeyPressed" :

text = getObject("text")
val = 0

function increment(i)
    return i + 1
end

function onSceneUpdate()
    setText(text, val)
    if isKeyPressed("W") then
        val = increment(val) -- Calling function increment
    end
end

It's named increment only for logic sake.
Function arguments are only local to the function so it's generic like a rule or a mathematical function.
When you call the function you pass it any variable in argument.

Re: Some basics.

THATS AWESOME! Imagine the possibilities with this! big_smile Thanks for the help.

Re: Some basics.

I have made a working ammo-system now and I'm about to script an AI system. Is there any good ways to go about this?
I will also script some kind of a hitbox, I'm not sure how to do this as well.

/P

Last edited by Pär (2012-12-28 09:48:58)

Re: Some basics.

Pär wrote:

I have made a working ammo-system now and I'm about to script an AI system. Is there any good ways to go about this?
I will also script some kind of a hitbox, I'm not sure how to do this as well.

/P

Hey Par! I have been waiting to share some ideas about the way my idea of a game engine would work, and I have thought of an AI system (at least how it would work).

I think the best AI system is one that simulates our own intelligence in real life. All humans have 5 senses. Sight, Hearing, Smell, Taste, and Touch.

If you build a SENSES SYSTEM, then you can give whatever object you want a sense of Artificial Intelligence. You basically create some SENSE OBJECTS. I will give a brief demo:

TOUCH:
Touch is basically simulated using COLLISION detection. Giving an entity the ability to sense when it is colliding with something is simulating the sense of TOUCH.

SIGHT:
Sight also uses collision detection. Attach a CONE to the front of an object. This will be the FIELD OF VIEW. Anything that collides with the cone is SEEN! (The cone must not have physics. In other words, it shouldn't react to the collision). The width of the cone simulates how wide the object can SEE. The transparency of the cone would simulate how WELL the object can see (more transparent means worse sight). The LENGTH of the cone would simulate near or farsightedness.

HEARING:
Hearing uses a PROXIMITY system. The closer you get to an object that makes sound, the HIGHER THE VOLUME and PITCH of an object gets (Doppler effect). The Hearing() function basically turns up the volume of an object the closer you get. You could also use a SPHERE as your FIELD OF HEARING and make a proximity system based on how far an object is from the center of the sphere.

SMELL:
Smell uses a PARTICLE SYSTEM. Odors act more like particles. The smell system is just a sphere that can detect when a particle has entered it. If a particle has entered the sphere that particle system is SMELLED!

TASTE:
Taste  is just a collision detection also. Works like the TOUCH system. But the taste object is just located near a mouth.


All these senses are FUNCTIONS:

Touch()
See()
Hear()
Smell()
Taste()

And all the things they can sense are entities/objects:

box
man
radio
particleSystemGas
meat

And when these senses get triggered, things happen:

Fall()
Wave()
Dance()
Frown()
RubTummy()

Take Care!

-TD

Last edited by Tutorial Doctor (2013-09-01 17:05:52)

Re: Some basics.

Thanks for the long explanation. I think it works, sound like a good idea.

I like the seeing, a big cone. Haha smile

I'm right now making an AI-system, it's the most fun of it all. Right now I'm trying to figure out how to make objects look at certain objects using the Z-angle. Trying to do the math. Gonna keep it up. So thanks for the answer. smile

Re: Some basics.

HI par,

This may help, that instead of you having to reinvent the wheel ( where you could concentrate on other things in your game instead) you could bring it into Maratis, though I have no idea how that would be done , my self not  being a master programmer , but anyway its here:

http://code.google.com/p/raick/wiki/Lua

I clearly have no idea if its what you're after but it might save you valuable time if it is, and help others as well looking for similar things.

Re: Some basics.

It can clearly save time and seems pretty easy to use, I have used lua since christmas and this seems effective. So thanks for the link, I'm sure I will have some use for it. wink