PDA

View Full Version : Inventory



sirlich
10-05-2009, 05:14 PM
-- Project: Continued from this post. (http://www.rtsoft.com/forums/showthread.php?p=11507#post11507)
To create a separate rpg-type graphical Inventory screen.

--Progress:
So far I've been able to place items in the world for the Player to "pick-up" by way of a "mouse right click" menu (though I haven't figured out yet why I need to double-click on that dialog menu to activate the choices) and then transfer these objects to players inventory using the basic example in the RPG World...

My next step was to create a map called "Character Screen" and add the option in the player_menu.lua to go to the new map... which worked fine... EXCEPT:

1. the original map scripts continue to run... which isn't good.
2. Haven't figured out how to return to the original map when the Character Screen is "closed" without using a specific map name.

I'm fairly certain I need to get back to the original map by way of finding the Player entity and then calling the map it's on... haven't completely figured it out yet though and any help on this would be appreciated.

Seth
10-06-2009, 12:30 AM
Right - here are ways to do that. First you need to get the player entity.

Two ways - if you've set it using GetGameLogic:SetPlayer(playerEnt) at some earlier time (most of the examples do this), you can do this:


GetMapManager:SetActiveMapByName(GetPlayer:GetMap( ):GetName());

Or, instead of using GetPlayer, you could do the same thing for ANY named Entity in any map (you should use SetName() on it first) in the game by doing:


ent = GetEntityByName("Player");

then the next part is the same:

GetMapManager:SetActiveMapByName(ent:GetMap():GetN ame());

Note: I just thought of a problem.. you can't pause the game properly.

I haven't exposed the C++ command "GetGameLogic()->SetGamePaused(true);" to script yet.

If you set all your item/dialog entities with ent:SetPriorityLevel(C_PRIORITY_LEVEL_HIGH); this would cause them to continue running while the rest of the game is paused, if you could use the above SetPause() command.

(otherwise some entities may continue to run in the game, well, if you put any on a watch list.. (so entities can chase people through doors, etc) )

I'll add this in the next update... if you don't use watch lists, you really don't have entities running when the map is off the screen and you don't have to worry about it.

sirlich
10-06-2009, 01:38 PM
GetMapManager:SetActiveMapByName(GetPlayer:GetMap( ):GetName());


--Worked... Thank you.


Note: I just thought of a problem.. you can't pause the game properly.

I haven't exposed the C++ command "GetGameLogic()->SetGamePaused(true);" to script yet.

If you set all your item/dialog entities with ent:SetPriorityLevel(C_PRIORITY_LEVEL_HIGH); this would cause them to continue running while the rest of the game is paused, if you could use the above SetPause() command.

(otherwise some entities may continue to run in the game, well, if you put any on a watch list.. (so entities can chase people through doors, etc) )

I'll add this in the next update... if you don't use watch lists, you really don't have entities running when the map is off the screen and you don't have to worry about it.
Yeah, in the your rpg example, the maid (assuming the Dad as well), continues running her goal script... the GamePaused would definately be useful.
Until then, I'm going to try to maybe pause that by leaving/opening another dialog menu on the current map, at the same time as (or just before) the call is made to switch to the Character Screen Map. --Will work on that tonight. Though the real problem might be how to automatically close that new dialog when returning to player's map so that you don't return just to have to choose another option on a dialog menu...

--Still studying and learning. Teaching an "old dog new tricks" not that easy.

sirlich
10-06-2009, 04:14 PM
...Until then, I'm going to try to maybe pause that by leaving/opening another dialog menu on the current map, at the same time as (or just before) the call is made to switch to the Character Screen Map. --
.

Nevermind... seems dialogs will only be continued on the new map.. not on original map... hm.

sirlich
10-11-2009, 07:48 PM
This is slightly off-topic and a deviation of my original project but, in a way, could be a necessary component to my Inventory screen. Mouse_overs...

Using the script mouse_button.lua (in base) with m_bIsInsideRect and GetInputManager:GetMousePos() and slight modification, I've managed to get the description of user-activated objects on mouse-over. However, in order to get this, the script must be written into that particular entity's script...

My intention would be for it to be global, so that it would'nt be necessary to rewrite it in every single entity script... for example: whenever the mouse is over ANY entity that is of a particular C_TYPE_ and to have that description in a small window...(the latter of which, I'm fairly certain, IS NOT possible with Novashell at present) instead of the plain dialog.

I've tried binding the mouse and inserting the script into game_start.lua but it seems to just ignore it.

Any suggestions?

Edit: Another question pops up -- using the mouse position and "if (ent:GetName() != "") then" instead of "m_bIsInsideRect", is the same thing accomplished or does that actually require a "click"

Seth
10-12-2009, 12:02 AM
You can definitely do both of those things, it's just a question of how you want to.

I'd probably be using an item database (like the one in the RPG example) , and "on-the-fly" spawning items and setting their data all using the same item script, that could be based on the button one.

Using Entity:Data() you can set any amount of extra data in an entity on the fly, and the script can use that to grab the description, graphic, etc.

To show items on mouse over without needing a click, you need to constantly be polling what is under the mouse and sending that item a message or something.

Two ways to do that:

1. Have each item script run a function every 100 MS that just the current mouse position and tests to see if it's under it

2. Instead of above, make a special mouse script that does the same thing, that way, no matter how many items you have there is only one check per frame, so things won't slow down. If it sees an item under its position, it can send data to the item in question.

This is some pretty advanced scripting stuff. In the mouse controlled RPG example, in the player script, there is code that shows how to convert a mouse coordinate into world coordinates and check to see what entities it is touching.

sirlich
10-12-2009, 03:44 PM
...
I'd probably be using an item database (like the one in the RPG example) , and "on-the-fly" spawning items and setting their data all using the same item script, that could be based on the button one.

Using EntityData() you can set any amount of extra data in an entity on the fly, and the script can use that to grab the description, graphic, etc.

Yeah, that is my original intent... I was jus waiting to connect the database/table to the objects until I figured out the mouse_over thing. Which I think I've figured out.


...
To show items on mouse over without needing a click, you need to constantly be polling what is under the mouse and sending that item a message or something.

Two ways to do that:

1. Have each item script run a function every 100 MS that just the current mouse position and tests to see if it's under it

2. Instead of above, make a special mouse script that does the same thing, that way, no matter how many items you have there is only one check per frame, so things won't slow down. If it sees an item under its position, it can send data to the item in question.

This is some pretty advanced scripting stuff. In the mouse controlled RPG example, in the player script, there is code that shows how to convert a mouse coordinate into world coordinates and check to see what entities it is touching.

Your right: definately advanced scripting... at least for someone at my level of programming knowledge! :sweatdrop: What I was doing wrong, pretty sure anyway, was trying to get the mouse-over code written into the main game script (e.g. the game_start.lua or the player.lua) or resign myself to leaving it in the actual objects script (e.g. sword.lua)...

Instead... (if I understood your suggestion correctly-- tho even if I didn't, It worked), what I did was create a general object script (named: obj_util.lua), placed the following code into it, and then had that weapon entity, that was placed on the map --along with ALL other objects that would need it -- use that same generic script in the entity's property window! (here I was, trying to call a "RunScript" to it in the code of each individual entity script instead... D'oh)


//--------------- BEGIN MOUSE-OVER
m_bIsInsideRect = false;
function OnInit() //run upon initialization
GetInputManager:AddBinding("mouse_left", "OnMouseLeft", this:GetID());
this:SetRunUpdateEveryFrame(true);
this:Data():SetIfNull("OnClick", 'LogMsg("Clicked!");');
end
function OnPostInit() //run during the entity's first logic update
end
//this is run every logic tick
function Update(step)
local pt = ScreenToWorld(GetInputManager:GetMousePos());
r = this:GetWorldRect();
if (r:IsInside(pt)) then

if (m_bIsInsideRect == false) then
m_bIsInsideRect = true;
OnEnteredRect();
end

else
if (m_bIsInsideRect ) then
m_bIsInsideRect = false;
OnLeftRect();
end
end
if (m_bIsInsideRect) then
//how about a little rotating effect?
local rot = math.sin(GetApp:GetGameTick()/300)/10;
this:SetRotation(Lerp(this:GetRotation(), rot, 0.011*step));
else
local rot = this:GetRotation();

if (rot != 0) then

//slowly move it back to the normal position
this:SetRotation(Lerp(rot, 0, 0.011*step));
end
end
end

function OnEnteredRect()
//this:GetBrainManager():Remove("Scale"); //make sure a pending scale isn't happening
this:GetBrainManager():Add("Scale", "scalex=1.1;scaley=1.1;scale_speed_ms=500;");
GetTextManager:Add("You see " .. this:Data():Get("OnActionText"), this); // insert call to itemDB instead...
end
function OnLeftRect()
this:GetBrainManager():Add("Scale", "scalex=1.0;scaley=1.0;scale_speed_ms=500;");

end
function OnMouseLeft(bKeyDown)

//we only care if they pressed down the button, not if they are releasing it
if (bKeyDown == false) then return true; end;
if (m_bIsInsideRect) then
ScheduleSystem(0, C_ENTITY_NONE, this:Data():Get("OnClick"));
return false; //Don't let any other callbacks be called
end
return true; //Let other callbacks get called
end
//------------------------ END MOUSE-OVER

Basically a copy of the mouse_button.lua (I liked having the rotating effect on objects just for the sake of players being able to notice objects that can be interacted with.)

Next steps are to connect to the itemDB and incorporate my RightMouseClick menu to add items to the inventory... though, this time around... using this one single generic object script (obj_util.lua) to do them in.

sirlich
10-13-2009, 02:21 AM
---Got mouse-over coded to give descriptions on objects.
---Got the RightMouseClick to bring up a dialog menu for those objects
---Got the LeftMouseClick for movement (as in the mouse control example) and displays a message saying "Taking a closer look at.." as shown below:


if (ent != nil) then

//approach is different then move, it understands you want to face an object and calculates
//a good place to stand.
if (ent:Data():Get("OnActionName") != "") then
GetTextManager:Add("Let's take a closer look at " .. ent:Data():Get("OnActionName"), this);

end

this:GetGoalManager():AddApproach(ent:GetID(), C_DISTANCE_CLOSE);
return true;

end

if (this:IsValidPosition(this:GetMap(), pt, true)) then
this:GetGoalManager():AddMoveToPosition(pt);

else
GetTextManager:Add("I can't move there!", this);
end

And everything works fine... except:
When "escape" is hit... then dialog choice is clicked to take player to my Character/inventory screen (new map) and then closing that screen... the above code will then produce 2 ("Let's take a closer look at ") statements... and if the character screen is opened and closed again... will produce 3 of those statements and so on...

Do I need to clear something to fix that?

Seth
10-13-2009, 02:57 AM
When "escape" is hit... then dialog choice is clicked to take player to my Character/inventory screen (new map) and then closing that screen... the above code will then produce 2 ("Let's take a closer look at ") statements... and if the character screen is opened and closed again... will produce 3 of those statements and so on...

Do I need to clear something to fix that?

Hmm.. sounds like multiple instances of your script are being activated?

Maybe you need to kill it when you exit the inventory screen?

Also, if this is on your inventory screen and you don't have anybody walking up to them, you can remove the following:


this:GetGoalManager():AddApproach(ent:GetID(), C_DISTANCE_CLOSE);
if (this:IsValidPosition(this:GetMap(), pt, true)) then
this:GetGoalManager():AddMoveToPosition(pt);

else
GetTextManager:Add("I can't move there!", this);
end

sirlich
10-13-2009, 12:12 PM
Hmm.. sounds like multiple instances of your script are being activated?

Maybe you need to kill it when you exit the inventory screen?



Thinking the following code is doing just that...


function OnPlayerMenuResponse(text, key, dialog) //dialog is passed as a SpecialEntity
if (key == "quit_and_save") then
return DefaultEscapeHandler(); //really let them quit
end;

if (key == "char_scrselect") then
RunScript("~/../gui/character_map.lua");
end;
end

Tried using MapManager to just switch maps but found that the rest of the functions that I needed while in the Character Screen wouldn't run or at least not properly, which is why I called the script instead.

In the Character Screen, I close by:


function OnCloseCharScreen()
GetMapManager:UnloadMapByName("Character Screen");
LogMsg("Character Screen closed");

GetMapManager:SetActiveMapByName(GetPlayer:GetMap( ):GetName());

//------>Trying to get it so that closing the CharScreen then opening another dialog
//------ doesn't activate the mouse movement on closing that dialog... neither of these has worked yet.
//GetPlayer:RunFunction("SetupInputKeys");
GetPlayer:RunFunction("OnDialogCloseNotify");
end

The question is: So how do I kill the Character Screen script on closing?

Seth
10-13-2009, 01:48 PM
Hmm, well, I'd have to see where the entity that is doing the polling to check the mouse in the loop is being initted, you might want to do SetName("myPollingScriptThingie") so you can find it and kill it later by name when you close the menu.

Something like this:


ent = GetEntityByName("myPollingScriptThingie");
if (ent != nil) then
//found it
ent:SetDeleteFlag(true);
end


But you're right, if the entity that is controlling the script was initted on the inventory map, it should automatically die when the map is unloaded.

I was going to tell you to use the "Show named entities active" option from the editor to help debug this, but was surprised to find I don't have that option... hmm, added todo list.

As long as you name your scripts that would help you to see when/if you end up with duplicates of 'em.

sirlich
10-13-2009, 02:17 PM
I just thought of something...

If I were to RunScript("character_map.lua") in start_game.lua so that the map is loaded and the script is running ALL the time, then SetActiveMapByName to it when needed and close with UnloadMapByName (or would I even need to unload it since I'm setting the active map by finding the Player anyway? --though I wonder about performance issues leaving the character map loaded.), would the script redundancy be solved...

The main issue I'm having I think, is with the key/mouse bindings, since number one: the player is controlled by mouse and the character map along with the various dialogs will use the same binding for a different function... Now I know that the binding is overridden when on the dialogs and currently, when I call to the Character Screen script and reset (by adding new bindings to those devices), which eliminated (...er, for the most part) the Player accidently moving when closing those dialogs/screen (for example: clicking "Exit" on a dialog will actually tell the Player to move on closing dialog -- this I fixed by Removebinding on the DialogOpen). But... if I have the script running all the time... hmm.

Well time to totally screw up my scripts and just see what happens in this case...

Seth
10-13-2009, 02:31 PM
Ok, here's the thing, RunScript processes a script one time, and adds its functions to the global names space. (or entity's namespace, if it's run from there)

Running it multiple times doesn't do anything, and you can't do loops or anything in its main script part. In fact, in general, you shouldn't even be doing anything in it except defining functions to call later, or it's confusing.

If you want something that loops and "stays alive", then you really need to just create an entity and give it a script. Then you kill the entity if you ever want the script to die. (You can make the entity invisible or just put it on a layer that isn't displayed to the player)

You can attach the entity to the camera if you want it to 'follow' you around no matter what map is active. (The RPG and Dink example do this for the status GUI bar thingie)

Actually, I just remembered, there IS a way to create a pure loop without using an Entity, check RT_LowRes\script\game_loop.lua for an example..


//Startup a game loop, this function gets called after all entities run their logic each frame

GetGameLogic:AddCallbackOnPostLogicUpdate("OnGameLoop", C_ENTITY_NONE);

//this is run every logic tick
function OnGameLoop(step)

LogMsg("Whee, I'm looping!");
end


Although I don't think you can turn off a global loop like this... so you sort of need to have it constantly detect what mode the game is in and behave accordingly. (Like, if you're on the title screen, it should check a global or something to know that)

sirlich
10-13-2009, 02:48 PM
Ok, here's the thing, RunScript processes a script one time, and adds its functions to the global names space. (or entity's namespace, if it's run from there)

Running it multiple times doesn't do anything, and you can't do loops or anything in its main script part. In fact, in general, you shouldn't even be doing anything in it except defining functions to call later, or it's confusing.

If you want something that loops and "stays alive", then you really need to just create an entity and give it a script. Then you kill the entity if you ever want the script to die. (You can make the entity invisible or just put it on a layer that isn't displayed to the player)

You can attach the entity to the camera if you want it to 'follow' you around no matter what map is active. (The RPG and Dink example do this for the status GUI bar thingie)

Actually, I just remembered, there IS a way to create a pure loop without using an Entity, check RT_LowRes\script\game_loop.lua for an example..


//Startup a game loop, this function gets called after all entities run their logic each frame

GetGameLogic:AddCallbackOnPostLogicUpdate("OnGameLoop", C_ENTITY_NONE);

//this is run every logic tick
function OnGameLoop(step)

LogMsg("Whee, I'm looping!");
end


Although I don't think you can turn off a global loop like this... so you sort of need to have it constantly detect what mode the game is in and behave accordingly. (Like, if you're on the title screen, it should check a global or something to know that)

Ah, I see. This opens up a ton of possibilites, (or a whole can of worms in my case :P) Thanks. An "invisible" entity on the Character Screen running the Character screen script actually sounds like what I'm looking for at the moment...

NinjaNumberNine
12-14-2009, 03:39 PM
How did you go about making an inventory? I would like to have one where a small bar/box pops up and shows five or six icons which, when clicked, apply the given power to the player. Is this possible? I don't want to actually go to another map, just pause the level, pop up an inventory box over the level, and Viola.

Thanks!


NNN

NinjaNumberNine
12-25-2009, 03:44 AM
Please, somebody! I'm not exactly desperate but I am releasing the first development package for BioTux on the first of January (that only gives me a week to get it ready) and I don't have ten percent of the features I had hoped I would have by now... There are a lot of stumbling blocks in the code ahead:


I need to learn how to better handle the visual profile. This is number one, cause I can draw all the attack/climb down pipe/toboggan etc animations but they are no help if I don't know how to integrate them... I have to date failed to see ANY reference (besides the link to it) of the contents of the XML. For example, I don't see where in the Player Lua it mentions

if "this key"/"that key" is/are held down,
or if "is_on_pipe"=true
this: set visual profile: "blah_blah"
(I know that's not code, but that's the jist of it)
I want to learn the particle system. Specifically, is there a way to create a 'square' of emitting particles confined to a space, instead of trailing off into the distance? (for water, and yes, I would have a seperate entity to set the gravity lower and the visual profile to "swim")
Is there a way to create a simple animation from two "TilePics" without having to stop and make a *.lua and *.xml? This is a very long process, and it complicates things as well. I was very disappointed to find that GIF was not supported... that would have opened so many possibilities...
Lastly, How can you remove some, not all, of the physics effects? Cool as it looks, being able to bounce a different height with subsequent jumps is NOT very "Puzzle" level-friendly, if you know what I mean...


One last thing: I have not been able to make NovaShell work on either of two Linux operating systems. (OpenSUSE, RPM based, and Ubuntu/Kubuntu, DEB based) It always comes out with a "./novashell: error while loading shared libraries: libclanApp.so.1: cannot open shared object file: No such file or directory" error. I read the "official" fix for this, switching the library directory, but it didn't help... I am making this game for Linux originally, and now I can't even run it on that platform... I had trouble enough compiling ClanLib in Ubuntu.

Sorry for the ravings, but they're from one in need (possibly of a good whipping) :sweatdrop:

Thanks,


NinjaNumberNine

NinjaNumberNine
12-27-2009, 03:01 AM
Please, anyone? :(

Seth
12-27-2009, 03:45 AM
Hey NNN,

Sorry I've been pretty busy on other things but I'll do my best to give you some answers.

1. The visual profile system has some special names that are automatically recognized - this makes it easier to share them between different games if people use these standardized names.

For instance, if a visual profile is named idle_left, this is the animation that will be played if the brain state active is currently Idle (http://www.rtsoft.com/novashell/docs/api/files/StateTopIdle-cpp.html).

In script, you tell the entity to enter the idle state like this (http://www.rtsoft.com/novashell/docs/api/files/BrainManager-cpp.html#BrainManager.SetStateByName):

this:GetBrainManager():SetStateByName("Idle");

You can get the full list of 'built in' brain states in the scripting reference (http://www.rtsoft.com/novashell/docs/api/files/main-h.html) by clicking "States" on the sidebar on the left.

So now that you know how to set a state, how do you detect a key press? Check out some of the example player scripts, it's all contained in there, you'll see how that works pretty easily I think.

Now, what if you have some special animations that you want to play that don't fit nicely into the state system? For that, check out the ForceVisual (http://www.rtsoft.com/novashell/docs/api/files/BrainForceVisual-cpp.html) brain. You can add this brain to override the visuals by just knowing the name of the animation in the visial profile xml.

For things that don't use the brain system, use Entity:SetAnimByName() to achieve the same effect.

2. Set a rectangular area particle emitter? Hmm, I don't think you can currently do that with what I have.

3. No there isn't, a tilepic is stuck being static, so even for something simple like an animated water tile you have to make a visual profile.

Well, actually a simpler way would be to make an entity, assign it a script and have the script use this:SetImage("water_anim1.jpg", NIL); wait half a second, then call this:SetImage("water_anim2.jpg", NIL); for a cheap way to do it.

The tiles need to be in any map directory for it to find them. So, still a hassle to make a script, but not so bad.

4. Do Entity:SetCollisionCategories(C_CATEGORIES_NONE); (http://www.rtsoft.com/novashell/docs/api/files/EntityBindings-cpp.html#Entity.SetCollisionCategories) from an entity and he will no longer collide with anything. You can still get collision callbacks (you still want to know when a shape hits, say, a coin to pickup) by using Entity:SetCollisionListenCategory (http://www.rtsoft.com/novashell/docs/api/files/EntityBindings-cpp.html#Entity.SetCollisionListenCategory).

You should also set the map's gravity to 0 so entities don't fall.

From that point, just figure out where stuff should be on your own in your own script loops and use Entity:SetPos(Vector2(100,100)); or whatever to set its position every frame.

About inventory: Uh... well, there is really no built-in inventory support, so you're sort of on your own there, there are many ways to go about that. Think of it as a mini-game you have to program.

If it was me, I would probably do that part in C++ as a plugin 'brain', but it surely is possible to do in pure scripting.

NinjaNumberNine
12-27-2009, 04:13 PM
Thanks for the quick reply, Seth. It was really informative- that's about all I need (for now). One or two things I did just think about, though- how can you make a coin pop out of a block and then let the block explode? Also I'd like to know how to actually kill an enemy by jumping on it, instead of using slasher.

Thanks,

NNN

Seth
12-28-2009, 01:13 AM
Check the scripts from Treeworld, it does the block breaking with head thing. To make it also pop out a coin you would need to create a coin in script about when it dies.

To detect when you jump ON an enemy, you would look at the incoming unit vector of the collision in the enemy's OnCollision listener. Basically the opposite of what the brick's script is doing. (It makes sure you are coming UP and hitting with your head, so you just need to flip the direction)

NinjaNumberNine
12-28-2009, 03:02 AM
Okay thanks- that'll hold me for a while- even though the Vector2 thing is a bit confusing... :sweatdrop:

Regards, NinjaNumberNine

NinjaNumberNine
12-29-2009, 07:22 PM
Check the scripts from Treeworld, it does the block breaking with head thing. To make it also pop out a coin you would need to create a coin in script about when it dies.

How do you call an entity from another entity's script? I've been experimenting but nothing works.. Programming's like that, i guess, no guessing allowed. :o

Seth
01-02-2010, 01:31 AM
How do you call an entity from another entity's script? I've been experimenting but nothing works.. Programming's like that, i guess, no guessing allowed. :o

Not sure what the question is - are you wondering how to communicate with another entity from an entity, or create a new entity from withing an entity script?

NinjaNumberNine
01-02-2010, 04:36 PM
I had meant, how can you create/access another entity? Are their any "permissions" needed for that? For example, to create a coin, then make it move up and out of the block (which turns just changes from the "active" image to "unactive", How would you "call up" the other entity and tell it to replace yourself?

Sorry for the experience that I don't have... ;)

NNN

Seth
01-03-2010, 01:15 AM
Ok, considering the topic of this thread is inventory we've gotten off track, please make a new topic if you have any more questions.. it's just so it's easier for other people to find answers during searches. :sweatdrop: :sweatdrop:

But here is the answer - I think you want to know how to "spawn" a coin.

Don't replace the current entities graphic to look like a coin, it's cleaner to just make a coin object.

Check worlds/RT_TreeWorld/script/static/ent_brick.lua

When you hit this with the players head, it needs to make a bunch of 'brick chunks' to fly around. These are spawned entities, look at this function it has:


function AddDebris(vPos, vForce)

ent = CreateEntity(this:GetMap(), this:GetPos()+vPos, "misc/ent_brick_chunk.lua");
ent:AddForce(vForce);
ent:SetPersistent(false);
Schedule(800, ent:GetID(), "this:GetBrainManager():Add(\"FadeOutAndDelete\",'');");

end

This creates an entity and gives it the "misc/ent_brick_chunk.lua" script. (you could change this to the coin script and it would spawn a coin instead)

The parameters are a position offset and velocity so the chunks start moving.

The FadeAndDelete brain kills the chunks after a bit.

Notice it's making changes to the newly created entity (like with ent:SetPersistent(false); ) - you can also use ent:RunFunction("SomeFunc", optionalParms, etc); to run a function inside its .lua script/namespace.

The functions can return values etc, so this provides a way to communicate with other entities if you need to.

It actually calls it like this:


function Crumble()

//Bust up this brick
this:SetDeleteFlag(true);
GetSoundManager:Play("audio/mario/smash.wav");

//create the particles that fly off
AddDebris(Vector2(0,0), Vector2(-2,-2));
AddDebris(Vector2(20,0), Vector2(2,-2));
AddDebris(Vector2(0,20), Vector2(-1,-2));
AddDebris(Vector2(20,20), Vector2(1,-2));

end

function OnDamage(normal, depth, enemy, damage, userVar, projectile)
Crumble();
end

So you see it makes four chunks and makes them fly off in different directions.

These same concepts work fine for spawning anything.

NinjaNumberNine
01-03-2010, 02:20 AM
Wow, why didn't I think of that... :sweatdrop: I spent hours looking at those scripts, and I had changed the visuals around to suit my purpose... Guess I'll have to chalk it off to that dratty brain of mine... :D
Anyway thanks, and yeah I'm gonna need a new thread (maybe several)... I just got the first Biotux DR out the door, and found all kind of problems at the last minute... Maybe it's just me but at least 4 other people have tried (and failed) to get NovaShell to run under linux. Several versions of Linux. I had trouble getting Clanlib installed there as well... I know it's not your fault (as I blame most of it on me, the rest on ClanLib and whatever's left I say is Novashell's fault).
So, thanks for all and see you in the new thread! :D
NinjaNumberNine