• Advertisement

• Popular Now

• 9
• 10
• 9
• 10
• 10
• Advertisement
• Similar Content

• I'm having a weird issue with detecting a collision. I've tried everything I could find online but nothing seems to work. I have a brick object. It has a 2D Collider attached and I have also attached a 2D Rigidbody on it. I also have an EndScreen 2D Collider. The EndScreen 2D collider is tagged with "EndScreen". I am trying to detect when a brick collides with the end screen collider and simply print "game over" in the console.
This is my current code for this part of the program, it is attached to the bricks:
void OnCollisionEnter (Collision2D collision) { if (collision.gameObject.tag == "EndScreen") { Debug.Log("Game over"); } } Several things have happened depending on the set up. If I have the rigidbody 2D set as static, my ball object can still collide with the bricks, but I get no Log message. If I set it to Kinematic or Dynamic, I get absolutely no interaction between the ball and the bricks, and nothing when the bricks pass through the collider. I have tried to set the collider to a trigger and use OnTriggerEnter2D, no change. I have tried to put the rigidbody on the EndScreen object and tried to set it's body type to all 3 settings, no change. The only thing I can think of that I have not done is put the script on the EndScreen object and switch the tag to the bricks. The reason I have not done this is because I will have several types of bricks, some of which will have different tags.

Please tell me somebody can see what I'm doing wrong here, because I'm losing my mind over something I feel should be ridiculously simple. Thanks.

• Downloadable at:
https://virva.itch.io/sandman-academy
https://gamejolt.com/games/sandmanacademy/329088
https://www.indiexpo.net/en/games/sandman-academy
https://www.gamefront.com/@sandmanacademy
http://www.indiedb.com/games/sandman-academy

• Downloadable at:
https://virva.itch.io/sandman-academy
https://gamejolt.com/games/sandmanacademy/329088
https://www.indiexpo.net/en/games/sandman-academy
https://www.gamefront.com/@sandmanacademy
http://www.indiedb.com/games/sandman-academy

• Downloadable at:
https://virva.itch.io/sandman-academy
https://gamejolt.com/games/sandmanacademy/329088
https://www.indiexpo.net/en/games/sandman-academy
https://www.gamefront.com/@sandmanacademy
http://www.indiedb.com/games/sandman-academy

• Downloadable at:
https://virva.itch.io/sandman-academy
https://gamejolt.com/games/sandmanacademy/329088
https://www.indiexpo.net/en/games/sandman-academy
https://www.gamefront.com/@sandmanacademy
http://www.indiedb.com/games/sandman-academy
• Advertisement
• Advertisement

Unity SqPlus minimal examples

This topic is 4564 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

A simple/minimal example was missing from SqPlus: simple examples shown below. (Updated versions with the example code and additional info here: http://wiki.squirrel-lang.org/default.aspx/SquirrelWiki/SqPlus.html. The code should compile and link with no warnings or errors with VS.NET 2003 (should also work with VS8 beta2). If a GNUMakefile is created for GCC, let me know if there are any issues with GCC builds and I'll fix them). Minimal Hello World example:
#include "sqplus.h"

using namespace SqPlus;

int main(int argc,char * argv[]) {
SquirrelVM::Init();
SquirrelObject helloWorld = SquirrelVM::CompileBuffer("print(\"Hello World\");");
SquirrelVM::RunScript(helloWorld);
SquirrelVM::Shutdown();
return 0;
} // main


Minimal example with class binding:
#include <stdio.h>
#include "sqplus.h"

using namespace SqPlus;

class MyClass {
public:
int classVal;
// See examples in testSqPlus2.cpp for passing arguments to the constructor (including variable arguments).
MyClass() : classVal(123) {}
bool process(int iVal,const char * sVal) {
printf("classVal: %d, iVal: %d, sVal %s\n",classVal,iVal,sVal);
classVal += iVal;
return iVal > 1;
} // process
};

int main(int argc,char * argv[]) {

SquirrelVM::Init();

SQClassDef<MyClass>("MyClass").
func(MyClass::process,"process").
var(&MyClass::classVal,"classVal");

// Line continuations removed from this post to simplify formating.
SquirrelObject helloSqPlus = SquirrelVM::CompileBuffer("
local myClass = MyClass();
local rVal = myClass.process(1,\"MyClass1\");
print(\"Returned: \"+(rVal ? \"true\" : \"false\"));
rVal = myClass.process(2,\"MyClass2\");
print(\"Returned: \"+(rVal ? \"true\" : \"false\"));
print(\"classVal: \"+myClass.classVal);
");
SquirrelVM::RunScript(helloSqPlus);

SquirrelVM::Shutdown();

return 0;
} // main


This version also provides easy bindings for class/struct instance variables. See the SqPlus Wiki (link above) for more examples (including example code for using the remote debugger, more class binding examples including constants, static functions and variables, variable number of arguments, custom constructors and destructors, calling Squirrel functions from C/C++, passing class instances to/from Squirrel, etc.). [Edited by - John Schultz on October 21, 2005 1:31:04 PM]

Share this post

Share on other sites
Advertisement
Thanks, however, when I build it, I include the library folder to my library paths, and the squirrel folder and the sqplus folder to the include paths, and it still says it cant find squirrel.h, apparently this is being included in sqplus.h as if it's in the same folder ("squirrel.h"), amd I supposed to put these files in the same folder?

Share this post

Share on other sites
Quote:
 Original post by blankdevThanks, however, when I build it, I include the library folder to my library paths, and the squirrel folder and the sqplus folder to the include paths, and it still says it cant find squirrel.h, apparently this is being included in sqplus.h as if it's in the same folder ("squirrel.h"), amd I supposed to put these files in the same folder?

Load squirrel.sln
Right click on the minimalSqPlus project and select Properties
Select C/C++, then General
You'll see Additional Include Directories showing: ../include;../sqplus

Thus, for you own project, you'll need to set Additional Include Directories to: [your_location_for_squirrel_files]/include;[your_location_for_squirrel_files]/sqplus

Also be sure you have the latest version from: http://wiki.squirrel-lang.org/default.aspx/SquirrelWiki/SqPlus.html

Share this post

Share on other sites
So I compile that, and it gives me a library/libraries, link them to my project, but also include the include folder and the sqplus folder to my include paths, okay i'll try that.

EDIT: Thanks, it seems to work now. However, I've got a question. When I added the include paths, and I linked the pragmas, how does it know to use the library instead of the files that I include from the folders? If you even understand what I'm trying to say heh, if not it doesn't matter, just think it's redundant.

Thanks john for the help, you really seem to stand strong next to squirrel, as I hope I will. Hope to have a great time with squirrel, and maybe even write some tutorials.

[Edited by - blankdev on October 20, 2005 9:46:09 PM]

Share this post

Share on other sites
Quote:
 Original post by blankdevEDIT: Thanks, it seems to work now. However, I've got a question. When I added the include paths, and I linked the pragmas, how does it know to use the library instead of the files that I include from the folders? If you even understand what I'm trying to say heh, if not it doesn't matter, just think it's redundant.

The include directives are for (uncompiled) header files (only), whereas the pragmas are for linking compiled libraries. You could also skip the pragmas and use the IDE project (effectively a makefile system) to link the libraries instead.

Share this post

Share on other sites
Thanks, it works now like I said, I hope to do much with it, by the way, check your PMs.

Share this post

Share on other sites
To be honest, I would prefer the minimal example if indeed it was actually minimal and not really 3 examples in one!

Share this post

Share on other sites
Quote:
 Original post by KylotanTo be honest, I would prefer the minimal example if indeed it was actually minimal and not really 3 examples in one!

Done.

Share this post

Share on other sites
LOL YEAH WHAT KLYOTAN SAID! Anyways, nice job. I had to do it myself lol. Anyways, I've still been wondering what the difference between squirrel and sqplus are. I mean, in your examples, it shows no indication of what part is sqplus and squirrel. If I'm still able to bind classes and functions and variables in the normal squirrel, what makes sqplus better than that? I know it has more advanced features, but if for now all I need is this, what's the difference? Just wondering, I like the format though.

Also, how may I run a script from an external file? Such as lua has doscript or dofile (I forgot), would it be something like:

SquirrelVM::RunScript("script.squirrel");

Also, by the looks of it, I dont know if the extension for squirrel scripts is .squirrel, or could it be anything, thanks bud, just wanna get these off my chest.

Share this post

Share on other sites
Quote:
 Original post by blankdevLOL YEAH WHAT KLYOTAN SAID! Anyways, nice job. I had to do it myself lol. Anyways, I've still been wondering what the difference between squirrel and sqplus are. I mean, in your examples, it shows no indication of what part is sqplus and squirrel. If I'm still able to bind classes and functions and variables in the normal squirrel, what makes sqplus better than that? I know it has more advanced features, but if for now all I need is this, what's the difference? Just wondering, I like the format though.Also, how may I run a script from an external file? Such as lua has doscript or dofile (I forgot), would it be something like:SquirrelVM::RunScript("script.squirrel");Also, by the looks of it, I dont know if the extension for squirrel scripts is .squirrel, or could it be anything, thanks bud, just wanna get these off my chest.

Base/vanilla Squirrel can only bind functions with the following signature:
int func(HSQUIRRELVM v). All arguments must be manually processed from the call stack, return values must be pushed on the stack, etc.

All of the template interface code is SqPlus. See squirrel.h for the base Squirrel API, and SqPlus.h for the SqPlus template binding system.

See the Squirrels docs for sqstd_dofile() to load scripts from disk (typically named .nut (source) and .cnut (pre-compiled)).

Share this post

Share on other sites

• Advertisement