Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Getting Started

noob FAQ - Problem and Answers Only Pls

You feel lost? You don't understand how to use ShiVa?

Re: noob FAQ - Problem and Answers Only Pls

Postby gamescorpion » 12 Aug 2011, 04:38

ISSUE: How to use objects or call objects or connect them to script so you can manipulate them? (How to use tags?) PART 2: How do you make ObjectA point to ObjectB?

OUR SOLUTION: This was an answer I posted in another post, here is a quick basic solution that we use -

STEP BY STEP:

NOTE: Your scene must be loaded for this to work

1. Right click on the object in scene viewer and then click on Edit Tag.
2. Give it a name. EX -> objectA
3. Then in the script you assign it a variable like this:
local hObjectA = application.getCurrentUserSceneTaggedObject ( "objectA" )

4. CONGRATULATIONS, now you can do all kinds of things with hObjectA by using the object command.

EXAMPLE:
local nObjX, nObjY, nObjZ = object.getBoundingSphereCenter ( hObjectA )
-- Obtain the X, Y and Z CENTER Co-ordinates of hObjectA (Also known as objectA in the scene)

To the SECOND part of the question, how to make an object A, look at a second object B, simply do the following:

1. Get the sphere center of Object B (As i did in the above example, you will get the X, Y and Z)
2. Use object.lookat function on Object A and use the values obtained from the sphere center of object B and you will successfully make object A look at object B. This is the basic way to do it.
Game Scorpion Inc. http://www.gamescorpion.com
JOIN MY TRAINING AND APP RESOURCE MEGA SITE - App Dev Toolkit (The #1 Resource For App Developers):
http://www.AppDevToolkit.com
User avatar
gamescorpion
Platinum Boarder
Platinum Boarder
 
Posts: 656
Location: Ontario, Canada

Re: noob FAQ - Problem and Answers Only Pls

Postby gamescorpion » 13 Aug 2011, 19:07

ISSUE: How to do long comments or script comments or line comments in ShiVa?

OUR SOLUTION: ShiVa is coded with LUA scripts. LUA uses the following comment system:

-- SINGLE LINE COMMENT STARTS WITH TWO SINGLE DASHES SIDE BY SIDE

--[[
LONG BLOCK
STYLE COMMENT STARTS WITH TWO SINGLE DASHES SIDE BY SIDE FOLLOWED BY TWO SQUARE BRACKETS
SIDE BY SIDE - ALL FOUR CHARACTERS HAVE NO SPACE AND THIS RUNS UNTIL TWO SQUARE BRACKETS OF OPPOSITE DIRECTION ARE FOUND.
--]]

Notes:
Make sure when doing block comments there is no SPACES between the command to start the block comment -
EX:
--[ [
TEST
--]]

WILL FAIL!

Hope that helps someone on the comment system.
Game Scorpion Inc. http://www.gamescorpion.com
JOIN MY TRAINING AND APP RESOURCE MEGA SITE - App Dev Toolkit (The #1 Resource For App Developers):
http://www.AppDevToolkit.com
User avatar
gamescorpion
Platinum Boarder
Platinum Boarder
 
Posts: 656
Location: Ontario, Canada

Re: noob FAQ - Problem and Answers Only Pls

Postby gamescorpion » 14 Aug 2011, 09:48

ISSUE: What are atlases and how can I use them?

OUR SOLUTION: Okay in ShiVa we found that there are 2 areas that you can use atlases, in the HUD and in the actual meshes you import via script. Trouble is that there is no built in function that does texture atlases in the script section, so we have made one (who knows, maybe the ShiVa team may like it and use it in a future implementation as it is very easy to use) EDIT: HOWEVER PLEASE NOTE THAT DOING ATLASES OUTSIDE OF SHIVA WILL SAVE ON MEMORY! WHEN AT ALL POSSIBLE, DO ALL ATLASING OUTSIDE OF SHIVA ITSELF!

FIRST: What is an atlas?
An atlas, when it comes to game development, is any image that has many smaller images inside of it and is supposed to reduce the number of draw calls, image switches and save CPU usage. For example you could have an image that is 1024x1024 in size and may have FOUR 512x512 images inside of it.

USAGE:
1. The HUD atlas usage is already very well documented in the following article so we wont go into any info on it as there is no point to re-do a great tutorial.

http://www.stonetrip.com/developer/1432-create-an-atlas-in-your-hud

2. SCRIPT ATLASES

KNOWN LIMITATIONS: Our function does not work well with repeating textures. If however you have built an object which makes use of INDIVIDUAL textures, then this function works well, but repeating textures don't work well at the current time. For example, if you have individually placed textures in your DCC tool on an object (for example a character face texture) then you can use the atlas code without issues. If however you are working on a level that has a repeating texture, then the atlas code will not work at this time.

Step by Step:
1. Create a function in your AI called texture_atlas and then copy and paste the code below into that file (ENTIRELY, simply hit CTRL+A in ShiVa, delete, hit CTRL+A in the code section below, copy and then go back and paste into ShiVa).

2. Next import the TEST ATLAS image into ShiVa (Note: This is just for the tutorial, in future we are assuming you will make your own atlases). MAKE SURE that any image that you create personally uses the SAME locations for images as that is how you will call the images up via code.

3. CONCEPT: Basically the image atlas function we created here at Game Scorpion Inc. can use ANY image atlas you make out of a SQUARE area. Rows go up from the bottom left of the image. Columns go to the right, also starting at the bottom left of the image. For example, your first image position would be Column 0, Row 0 which would point you to the first position on the image that we have provided, namely, 0. Column 1, Row 0 would point you at the FIRST position. If you create your image texture atlases like this, the function will be able to increment through each position using this concept. This means that you can access any texture you want simply by stating its Column and Row.

Image

4. USAGE:

A. your model that you are using should be set to use the texture atlas in the materials section (before runtime). Make sure each sub-material is also setup with the same texture.

B. we now need to make sure that we select the object via tags (read my previous post on object selection via tags) in the script to get a handle on the object.

C. we simply go through each sub-material on the model and assign it one of the textures from the atlas.

D. make your texture atlas as a PNG file so you can also have transparent materials.

Below is the function details and usage example:

this.texture_atlas ( nBlockSize, nColumn, nRow, nImageSize, nSubset, hObject, nRotation )

Where:
nBlockSize = the size of the induvidual image blocks, in square format (so either 32, 64, 128, 256, etc. Any SQUARE size). Ex. 32 = 32x32 block size, 256 = 256x256 block size.

nColumn = the column on the image atlas (view example above on how colmuns would look). Columns are based on your texture atlas image. For example, a texture atlas that is 1024x1024 in size with 128 as the block size would have 8 columns ( 1024/128 = 8 )

nRow = the row on the image atlas (view example above on how rows would look). Rows are based on your texture atlas image. For example, a texture atlas that is 512x512 in size with 256 as the block size would have 2 rows (512/256 = 2)

nImageSize = the actual FULL image size of the atlas. 1024 = 1024x1024, 512 = 512x512, etc. THIS IS NOT THE SAME AS BLOCK SIZE. This is all blocks combined.

nSubset = the subset material of the model. For example if object GameScorpion_Object has 5 materials on it, it would have 5 subset materials starting from 0 and ending at 4.

hObject = the handle to the specific object.

nRotation = can be one of four rotations, 0, 90, 180 or 270. 180 is the usual setting, however as you go through your model, you can adjust this as you go along. Stick to only these 4 positions as other positions will mess things up.

USAGE EXAMPLE:

this.texture_atlas ( 128, 0, 1, 1024, 0, hGameScorpion_Object, 0 )
-- The above tells the system that the atlas is 1024x1024 in size of which each block is 128x128 in size. I want to set the 0 material on the hGameScorpion_Object to the block located at column 0, row 1. The rotation is normal rotation (NO ROTATION) of the block image, however the image is considered inverted, so you should see an inverted image. To fix simply rotate to 180.

this.texture_atlas ( 256, 2, 1, 1024, 1, hGameScorpion_Object, 180 )
-- The above tells the system that the atlas is 1024x1024 in size of which each block is 256x256 in size. I want to set the first (1) material on the hGameScorpion_Object to the block located at column 2, row 1. If we are using the image below (TEST ATLAS) we will see the texture in block 6 appear on an object (In this case the number 6 with a red border). I also have included a rotation, so your 6 should actually be looking like a 6.

THATS IT! ENJOY! :)

----------------
REQUIRED ITEMS BELOW:


The TEST ATLAS ( 1024 x 1024 PNG ) :

Image

The CODE:
Code: Select all

--------------------------------------------------------------------------------
--  Function......... : texture_atlas
--  Author........... : Game Scorpion Inc.
--  Description...... : Texture Atlas Function of Any Size Atlas
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
function intro_ai.texture_atlas ( nBlockSize, nColumn, nRow, nImageSize, nSubset, hObject, nRotation )
--------------------------------------------------------------------------------
   
    -- EX. Command: texture_atlas ( 256, 1, 1, 512, 0, hObject, 180)

    -- Make sure nBlockSize and nImageSize are not 0 or negative values
    if nBlockSize > 0 and nImageSize > 0 then
   
        -- divide the image size by the block size = row length/total rows
        local nRowLengthAndTotalRows = nImageSize / nBlockSize
               
        -- take the nBlockSize and divide it by nImageSize to get the SCALE SIZE of U or V PER BLOCK
        local nScaleSize = nBlockSize / nImageSize
       
        -- Calculate the U Offset by taking nColumnPosition and dividing by the nRowLengthAndTotalRows
        local nUOffset = nColumn / nRowLengthAndTotalRows
       
        -- Calculate the V Offset
        local nVOffset = nRow / nRowLengthAndTotalRows
       
        if nRotation == 90 then
            nVOffset = nVOffset - ( ( nRowLengthAndTotalRows-1 ) / ( nRowLengthAndTotalRows + 1 ) )
        elseif ( nRotation == 270 ) then
            nUOffset = nUOffset - ( ( nRowLengthAndTotalRows-1 ) / ( nRowLengthAndTotalRows + 1 ) )
        end
       
        -- run offset command
        shape.setMeshSubsetMaterialEffectMap0AdditionalUVOffset ( hObject, nSubset, nUOffset, nVOffset )
       
        -- run scale command
        shape.setMeshSubsetMaterialEffectMap0AdditionalUVScale ( hObject, nSubset, nScaleSize, nScaleSize )

        -- calculate total increment for rotation
        local nIncrement = 1 / nRowLengthAndTotalRows
       
        -- calculate total variation
        local nVariation = 1 / ( nRowLengthAndTotalRows + 1 )
               
        -- run rotation command
        shape.setMeshSubsetMaterialEffectMap0AdditionalUVRotation ( hObject, nSubset, nVariation + ( nIncrement * nColumn ), nVariation  + ( nIncrement * nRow ), nRotation )
   
    else

        -- Return error if the nBlockSize or nImageSize is less than 0
        log.error ( "Sorry the nBlockSize and/or nImageSize is less than 0, please check your code." )

    end
   
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------

Last edited by gamescorpion on 21 Sep 2011, 10:15, edited 1 time in total.
Game Scorpion Inc. http://www.gamescorpion.com
JOIN MY TRAINING AND APP RESOURCE MEGA SITE - App Dev Toolkit (The #1 Resource For App Developers):
http://www.AppDevToolkit.com
User avatar
gamescorpion
Platinum Boarder
Platinum Boarder
 
Posts: 656
Location: Ontario, Canada

Re: noob FAQ - Problem and Answers Only Pls

Postby gamescorpion » 21 Aug 2011, 09:10

ISSUE: How to protect your game from hackers/crackers?

OUR SOLUTION: This is just one method of prevention we found built right into ShiVa 1.9 which detects if the software is cracked. You simply place this code in the onEnterFrame of your main AI and if it detects that the software may be cracked/hacked it will automatically exit your game!

Code: Select all
   
    if application.mightBeCracked ( ) then
        application.quit ( )
    end


More details on this can be found on this post http://www.stonetrip.com/developer/forum/viewtopic.php?f=27&t=13192&start=0&hilit=sales
Game Scorpion Inc. http://www.gamescorpion.com
JOIN MY TRAINING AND APP RESOURCE MEGA SITE - App Dev Toolkit (The #1 Resource For App Developers):
http://www.AppDevToolkit.com
User avatar
gamescorpion
Platinum Boarder
Platinum Boarder
 
Posts: 656
Location: Ontario, Canada

Re: noob FAQ - Problem and Answers Only Pls

Postby gamescorpion » 10 Sep 2011, 04:06

ISSUE: How to get a time stamp or current time in HH:MM:SS format?

OUR SOLUTION: ShiVa apparently does not have a specific code for getting a time stamp or the current time other than specifically getting the current SECONDS in the day. From this we went ahead and created the following code that will convert the seconds in the day into usable variables called nHour, nMinute and nSecond. This will give you the CURRENT time on the device IN 24 HOUR TIME. If you want AM/PM you will have to write a simple if/then statement to check the HOUR to determine AM/PM status, but that should not be hard.

Code: Select all
    -- Get total seconds in day
    local nTime = system.getTimeOfDay ( )
   
    -- Get current hour
    local nHour = math.floor ( nTime / 3600 )
   
    -- Get current minute
    local nMinute = math.floor ( math.abs ( ( nTime / 3600 ) - nHour ) * 60 )

    -- Get current second
    local nSecond = math.floor ( nTime - ( nHour * 3600 ) - ( nMinute * 60 ) )


Hope that helps someone :)
Game Scorpion Inc. http://www.gamescorpion.com
JOIN MY TRAINING AND APP RESOURCE MEGA SITE - App Dev Toolkit (The #1 Resource For App Developers):
http://www.AppDevToolkit.com
User avatar
gamescorpion
Platinum Boarder
Platinum Boarder
 
Posts: 656
Location: Ontario, Canada

Re: noob FAQ - Problem and Answers Only Pls

Postby gamescorpion » 20 Sep 2011, 02:56

ISSUE: How to decrease development/coding/programming time?

OUR SOLUTION: As you start to learn how to use ShiVa, there are some VERY helpful tools that are built in that if you learn how to use, you will save HOURS if not DAYS of time depending on how much code you have. On our end for example, our current game has around nearly 10,000 lines of code spanning over 200+ scripts. In the LOG reporter, we only see the error, and not every time do we get to see WHERE in all those scripts is the error. Here are some useful tips and tools that will definitely help:

1. AIModel Editor ALL FUNCTION SEARCH TOOL ( Found in the AIModel Editor->Edit->Find )
This tool will search every single script for a certain word. This is invaluable for those times where the log reporter simply says that an error lies at a function like sound.play or something like that in which there is no reference to the script, simply just a line number. This is VERY useful during these times

2. You get the FOLLOWING WARNING: "Failed registering AIModel function..." -> This is when you simply go to that SPECIFC function or handler, and COMPILE that specific function/handler to figure out what the error is. The code wont load because you have a syntax error (probably a missing bracket or something silly) and so a compile will fix it up.

3. The log reporter simply shows you an ERROR, but you have NO CLUE where or what it is...-> This one can be a bit tricky at times. First step is to do a compile of the ENTIRE code to see if that returns any syntax errors (Game Editor->Game->Compile) and then go through the Script Editors OUTPUT. If you still dont find it there, then you'll be left to try other methods or worst case scenario walking through the entire code step by step.

4. Another known ShiVa bug we found is that ShiVa doesnt COMPILE before EXPORT. This means that your game will seem to run FINE outside until it gets to the point where there is an error (A basic error that ShiVa didn't deem as a big issue, like initializing a variable...the compiler will find it, but ShiVa export will not...). THIS IS WHEN YOU GET THE "IT WORKS IN SHIVA BUT NOT OUTSIDE OF SHIVA" issue. To fix this, simply compile your code INSIDE ShiVa first and you will then have to scroll through the output in the Script Editor to find the line numbers where the error exists. Usually we've noticed things like missing characters or missing VARIABLE declarations that make the game RUN fine in ShiVa but Run DIFFERENTLY outside of ShiVa. So if you ever get the issue - "IT WORKS IN SHIVA" and not outside ShiVa, then this is why usually this is happening...(I'm going to put an additional post for this specific point as it is a COMMON bug amongst most newbs who get so messed up (Took me several hours until I realized what was going on)

HOPEFULLY the above solutions will help you save some time as we had to learn those tips/tricks on our own, but that has helped us save now HOURS AND HOURS of time rather than searching and finding errors :)

ENJOY!

Nav
Last edited by gamescorpion on 21 Sep 2011, 10:09, edited 1 time in total.
Game Scorpion Inc. http://www.gamescorpion.com
JOIN MY TRAINING AND APP RESOURCE MEGA SITE - App Dev Toolkit (The #1 Resource For App Developers):
http://www.AppDevToolkit.com
User avatar
gamescorpion
Platinum Boarder
Platinum Boarder
 
Posts: 656
Location: Ontario, Canada

Re: noob FAQ - Problem and Answers Only Pls

Postby gamescorpion » 21 Sep 2011, 10:08

ISSUE: Game/Program works in ShiVa but outside of ShiVa it works differently or not the same at all...WHAT HAPPENED?!?!?!

OUR SOLUTION: 4. Another known ShiVa bug we found is that ShiVa doesnt COMPILE before EXPORT. This means that your game will seem to run FINE outside until it gets to the point where there is an error (A basic error that ShiVa didn't deem as a big issue, like initializing a variable...the compiler will find it, but ShiVa export will not...). THIS IS WHEN YOU GET THE "IT WORKS IN SHIVA BUT NOT OUTSIDE OF SHIVA" issue. To fix this, simply compile your code INSIDE ShiVa first and you will then have to scroll through the output in the Script Editor to find the line numbers where the error exists. Usually we've noticed things like missing characters or missing VARIABLE declarations that make the game RUN fine in ShiVa but Run DIFFERENTLY outside of ShiVa. So if you ever get the issue - "IT WORKS IN SHIVA" and not outside ShiVa, then this is why usually this is happening...(I'm going to put an additional post for this specific point as it is a COMMON bug amongst most newbs who get so messed up (Took me several hours until I realized what was going on)
Game Scorpion Inc. http://www.gamescorpion.com
JOIN MY TRAINING AND APP RESOURCE MEGA SITE - App Dev Toolkit (The #1 Resource For App Developers):
http://www.AppDevToolkit.com
User avatar
gamescorpion
Platinum Boarder
Platinum Boarder
 
Posts: 656
Location: Ontario, Canada

Re: noob FAQ - Problem and Answers Only Pls

Postby gamescorpion » 22 Sep 2011, 09:35

ISSUE: I get the warning: application.setCurrentUserEnvironmentVariable : invalid variable type.

OUR SOLUTION: After searching through forums like crazy, we realized how SILLY this error is and once again seems like a bug in ShiVa, but luckily we now know how to work around it. APPARENTLY ShiVa does not detect when there is a SPELLING mistake in any setting of an environment variable!!!!! (BIG ISSUE WHEN U ARE WORKING WITH OVER 10,000 LINES OF CODE TRYING TO FIGURE OUT WHY THINGS ARENT WORKING!)

Anyways, the way to fix this is to check all of your application.setCurrentUserEnvironmentVariable calls to see if there is ANY spelling error in any of the VARIABLE NAMES you are calling.

FOR EXAMPLE, SHIVA WILL LET THIS PASS AND RETURN WARNING:

Code: Select all
local nGameScorpion = 2
application.setCurrentUserEnvironmentVariable ( "nRankLoss", nGamScorpion )


NOTICE THE VARIABLE DIFFERENCE, nGameScorpion and nGamScorpion (MISSING THE LETTER "E" IN GAME)

TO FIX THIS:
Code: Select all
local nGameScorpion = 2
application.setCurrentUserEnvironmentVariable ( "nRankLoss", nGameScorpion )


Now the warning will go away and things will work. Can be frustrating when there is no real "error" location or issue and you are left wondering why things aren't passing through nor are you given any line number or even which script the code issue could be in...hope the ShiVa ppl can fix this in future :)

Nav
Game Scorpion Inc. http://www.gamescorpion.com
JOIN MY TRAINING AND APP RESOURCE MEGA SITE - App Dev Toolkit (The #1 Resource For App Developers):
http://www.AppDevToolkit.com
User avatar
gamescorpion
Platinum Boarder
Platinum Boarder
 
Posts: 656
Location: Ontario, Canada

Re: noob FAQ - Problem and Answers Only Pls

Postby giggsy » 22 Sep 2011, 09:53

Sorry to disturb your cool findings with a post of mine, but here's how I detect dead and not working code: do a C++ export every once and a while!
Then compile it with UAT and fix the issues.

This way I have found errors like this and even "dead function"-calls.
Although a C++ build can take up maaaaany minutes ... it's a nice task you can do parallel ;)
User avatar
giggsy
Platinum Boarder
Platinum Boarder
 
Posts: 1093
Location: Austria

Re: noob FAQ - Problem and Answers Only Pls

Postby gamescorpion » 22 Sep 2011, 12:51

giggsy wrote:Sorry to disturb your cool findings with a post of mine, but here's how I detect dead and not working code: do a C++ export every once and a while!
Then compile it with UAT and fix the issues.

This way I have found errors like this and even "dead function"-calls.
Although a C++ build can take up maaaaany minutes ... it's a nice task you can do parallel ;)


AWSOME! Any bit helps to make ShiVa amazing for all users, Thanks for the input! :) Feel free to add at any time as well, trying to build a full listing of common tasks to help out everyone :)

Nav
Game Scorpion Inc. http://www.gamescorpion.com
JOIN MY TRAINING AND APP RESOURCE MEGA SITE - App Dev Toolkit (The #1 Resource For App Developers):
http://www.AppDevToolkit.com
User avatar
gamescorpion
Platinum Boarder
Platinum Boarder
 
Posts: 656
Location: Ontario, Canada

Re: noob FAQ - Problem and Answers Only Pls

Postby Scribe » 22 Sep 2011, 21:37

giggsy wrote:Sorry to disturb your cool findings with a post of mine, but here's how I detect dead and not working code: do a C++ export every once and a while!
Then compile it with UAT and fix the issues.

This way I have found errors like this and even "dead function"-calls.
Although a C++ build can take up maaaaany minutes ... it's a nice task you can do parallel ;)


I always thought ShiVa export DOES compile script, but if it's broken it just skips it (except in C++ as it errors at compile time).
ShiVa 3D 1.9.1 | UAT 1.3.1
VS 2010 | Xcode 4.1 | iOS 5.0.1
PC: OS Windows 7 x64 | CPU Phenom II X6 | Memory 16GB | GFX Geforce 480GTX
MacMini: OS OSX 10.7 | CPU i7 3.4ghz | Memory 4GB | GFX ATI 6630M
Scribe
Gold Boarder
Gold Boarder
 
Posts: 286
Location: UK

Re: noob FAQ - Problem and Answers Only Pls

Postby gamescorpion » 29 Sep 2011, 22:29

ISSUE: Why is it that when I set a value in an AI code, it doesn't show up properly? I have several objects using the same AI...

OUR SOLUTION: WATCH OUT FOR SPECIFIC AI INSTANCES!! This is a very big important concept, more to deal with OO (Object Orientated) programming, but I will describe it here.

AN INSTANCE of an object is a SPECIFIC individual item. Think of it like a cell phone.

Lets say JOHN DOE has an iPhone. BILL SMITH also has an iPhone. They have the EXACT SAME phone...does that mean that they will have the EXACT SAME PHONE NUMBERS PROGRAMMED INTO THEIR PHONES?? Obviously not (EVEN THOUGH IT IS POSSIBLE TO DO), each phone is an INDIVIDUAL version of the iPhone OR a SPECIFIC INSTANCE of the iPhone.

The same way, the SAME AI model can have several SPECIFIC INSTANCES. We can have 2 enemy objects using an AI called AI_ENEMY for example however the first enemy may have a power level of 50% while the second enemy may have a power level of 75%. They are both using the exact same AI base code, but their INDUVIDUAL INSTANCES of that code are different and store different values.

Once again think back to the iPhone example. The two men above have the iPhone but their induvidual PHONES have different phone numbers in them. That is exactly how you can think of instances.

EXAMPLE:
Base Code - AI_ENEMY (Has variable in it called nPOWER)

Enemy 1 - USING (AI_ENEMY) has nPOWER = 50
Enemy 2 - USING (AI_ENEMY) has nPOWER = 75

if I create a function that will display a message in the log (log.message ( this.nPOWER () ) I will have TWO values show up because there are TWO instances of the AI_ENEMY running. One showing 50 and one showing 75.

If I want to change the power value for Enemy 1 to 60, I would do the following:
Code: Select all
    object.setAIVariable ( hEnemy1, "AI_ENEMY", "nPOWER", 60 )


If I wanted to change the power value for Enemy 1 and Enemy 2 to BOTH be 50 I would do the following:
Code: Select all
    object.setAIVariable ( hEnemy1, "AI_ENEMY", "nPOWER", 50 )
    object.setAIVariable ( hEnemy2, "AI_ENEMY", "nPOWER", 50 )


If I wanted to make Enemy 1 have power of 20 and Enemy 2 power of 100 I would do:
Code: Select all
    object.setAIVariable ( hEnemy1, "AI_ENEMY", "nPOWER", 20 )
    object.setAIVariable ( hEnemy2, "AI_ENEMY", "nPOWER", 100 )


And hopefully you get the idea now...

THIS CONCEPT OF INSTANCES IS VERY IMPORTANT as you may (as a n00b) decide to send a value to an enemy and you end up thinking you have changed ALL instances with a single command...that is incorrect!

EXAMPLE OF MISTAKE:
Code: Select all
    -- YOU BELIEVE THAT THIS COMMAND WILL MAKE ALL ENEMIES HAVE POWER OF 60
    object.setAIVariable ( hEnemy1, "AI_ENEMY", "nPOWER", 60 )


The correct way is that you have to change the value for EVERY instance. If you have 10 enemies, you must call those 10 ENEMIES via code and change EACH one of their variables individually.

One final time so you get it, using the same example above...If i wanted to ADD A PHONE NUMBER to 10 iPhones, I would have to go TO EACH INDUVIDUAL IPHONE (SPECIFIC INSTANCE) and add that phone number to each specifc phone's phonebook/contact list. Only then will all 10 phones have that new phone number.

This concept, though simple, can lead you to bugs if you dont know it as you may call several instances and try and change all values in ONE line of code as I outlined above lol. I've done that several times myself and then I had an "AH HA!" moment.

What makes matters even more challenging is when you forget this concept and compile the code only to find NO ERRORS and when you read through your code, it all makes LOGICAL sense...until you remember...SPECIFIC OBJECT INSTANCES!

Nav
Game Scorpion Inc. http://www.gamescorpion.com
JOIN MY TRAINING AND APP RESOURCE MEGA SITE - App Dev Toolkit (The #1 Resource For App Developers):
http://www.AppDevToolkit.com
User avatar
gamescorpion
Platinum Boarder
Platinum Boarder
 
Posts: 656
Location: Ontario, Canada

Re: noob FAQ - Problem and Answers Only Pls

Postby gamescorpion » 02 Oct 2011, 06:28

ISSUE: How do you make snow/rain/environmental effect?

OUR SOLUTION: Cool question, we figured it out, its quite simple AND FUN! You can do a lot of neat ideas with this following solution, so be creative, and use your imagination, simply changing colors and images (USE PNG FOR TRANSPARENT IMAGES), you can easily create snow, rain and even FIRE STORMS!!

REQUIREMENTS: We assume that you already have a scene with a default camera in it. For this example we will assume that you have given the MAIN GAME CAMERA a tag called "game_cam". (Later you can change it to anything, but for this example we are using this)

STEP BY STEP:
THREE PARTS - A (Setup of Particles), B (Setup of Camera), C (Setup of Code)

A - Setup of Particles:
=======================
1. Click on the top left corner of any window and select the PARTICLE EDITOR
2. Click "Particle System" menu and select Create (Particle System->Create) and name it "Snow_SFX" or anything pertaining to snow.
3. In the General box, make sure that "AUTO START" is not selected and that only the "Use asynchronous update" is the only checkbox selected
4. Click on the heading below the General called "Emitter"
5. Select the Type as "OMNI"
6. Click on the heading below the Emitter area called "Particles"
7. Here are the settings to use:
Generation -
Max: 64 (You can change this as you wish)
% Initial: 0.03
% New / s: 0.32
Texture Map: DefaultFoam (Later you can use any texture you wish)
Additive Blending: CHECK THIS BOX!!!!
Life Time -
Max: 0.13
% Random: 0.0
Initial Speed -
Max: 0.75
% Random: 0.0
Rotation -
Max: 0.0
% Random: 0.0
Gravity -
Max: 1.0
% Random: 0.0
Friction -
Constant: 0.13
Time -
Key 1: 0.04
Key 2: 0.04

8. Click on each color and set the FOUR colors to the following REF hexadecimal values (You need to double click on the color to get the window of colors to pop up. Place the following hex values using copy and paste into the REF section!!!)
COLOR 1: 00FFDB
COLOR 2: 00BED6
COLOR 3: 3BB3CF
COLOR 4: FFFFFF

9. Continue completing the options
Opacity -
Initial: 0.19
Key 1: 0.27
Key 2: 0.50
Last: 0.58
Size -
Initial: 0.33
Key 1: 0.19
Key 2: 0.08
Last: 0.04
Global Scale: 1.0
% Random: 0.0

10. Save the entry (Particle System->Save)

B - Setup of Camera:
=======================
1. Open up your scene in the "SCENE VIEWER" (Click on the top left of any empty window)
2. Open up the "Scene Explorer" in another window (Click on the top left of any empty window)
3. Find the main default camera in the scene explorer and right click on it
4. Click on Edit Selection Tag
5. Name the tag "game_cam"
6. Right click again on the main default camera and this time select Attributes->Sfx->Add Particle Emitter and then select from the dropdown the name of the particle emitter you had created in PART A.
7. In another window open up the Attributes Editor (Click on the top left of any empty window)
8. Make sure you have selected the default camera in the Scene Explorer or else nothing will show up in the Attributes Editor
9. Select the Sfx Attributes bar (click the title bar called Sfx Attributes) in the Attributes Editor. If you do not see this title bar, then you need to confirm you completed step 6 above. If you have then MAKE SURE you have the default camera selected in step 8 above from the Scene Explorer.
10. In the Sfx Attributes, under the Emitters bar, you will see your sfx name there. Right click on this and click on Edit Position/Orientation.
11. Put the following co-ordinates into the Particle Emitter Attributes box:
Position: 0.0, 5.0, 0.0
Orientation: 0.0, 0.0, 0.0
12. Hit ok, and now SAVE YOUR SCENE by going to the "Scene Viewer" (Dont get confused with Scene Explorer) and clicking on Scene->Save. Close the scene by clicking on Scene->Close

C - Setup of Code:
=======================
1. In your main AI code in the init section simply add the following lines:
Code: Select all
        -- START SNOW
        local hCam = application.getCurrentUserSceneTaggedObject ( "game_cam" )
        sfx.startAllParticleEmitters ( hCam )


2. Run the program and you should now see a pleasant SNOW FALL!
3. To stop snow simply change the sfx code to stopAllParticleEmitters like this:

Code: Select all
        -- STOP SNOW
        local hCam = application.getCurrentUserSceneTaggedObject ( "game_cam" )
        sfx.stopAllParticleEmitters ( hCam )




AND THERE YOU HAVE IT...A SNOWFALL THAT YOU CAN SWITCH ON AND OFF THROUGHOUT YOUR GAME CODE SIMPLY BY STARTING AND STOPPING PARTICLE EMITTERS!

Now you can simply add many particle emitters to the camera for Rain, Fire storms, or whatever your creative mind can come up with!

PS: Try adding a second or even third sfx to the camera of the same type, just in different positions. This will give you more coverage when the camera is moving. Also the more particles you put in, the more FULL a scene will look, so for a HEAVY snowfall/rainfall like a blizzard, increase the amount of particles. If you want a light snow/rain effect, then keep the particles low. Another tip is to adjust various colors and texture maps. That will allow you to create things like fireflies, rain, snow, dust, etc.

HAPPY CODING!

Nav
Game Scorpion Inc. http://www.gamescorpion.com
JOIN MY TRAINING AND APP RESOURCE MEGA SITE - App Dev Toolkit (The #1 Resource For App Developers):
http://www.AppDevToolkit.com
User avatar
gamescorpion
Platinum Boarder
Platinum Boarder
 
Posts: 656
Location: Ontario, Canada

Re: noob FAQ - Problem and Answers Only Pls

Postby gamescorpion » 06 Oct 2011, 14:12

ISSUE: Game works perfect on PC, ShiVa and we finally also got it working PERFECT on apple iOS devices...NOW WHEN GOING TO "ANDROID", (After all compiling bugs have been taken care of and everything else works) it is showing up totally differently or has "in-game" bugs that are not in the other versions such as messed up sound/music, misplaced or wrongly translated objects (global translation issues) and other possible in-game issues...

OUR SOLUTION: Okay there are a LOT of issues that could be taking place, but here is what we did that fixed it ALL up for us and hopefully these few items will also fix up all the compile stuff for you too:

1. When you detect the device in the code in ShiVa (Usually on the init function), add the following line of code for the ANDROID part:
Code: Select all
        application.setMinFrameTime ( 0.02 )

NOTE: Don't know why it works, it just DOES

2. Have a CHECK to see in your code if you are using an ANDROID device and any GLOBAL TRANSLATIONS you make with object radius, you will usually have to downgrade to HALF...Weird but thats what we had to do (we had nRadius * 2 in iOS and Windows versions, but in Android version we used just nRadius which was the objects sphere radius)

3. SHIVA AUTHORING TOOL STEPS (UAT STEPS) ( UAT V1.2 as of writing this ) to make sure your music works...this is very important as it is what will fix up a LOT of basic issues:

A. ON STEP 3 of the compile in the Shiva Authoring Tool, make sure that ONLY "Use OpenGLES 1.1" is checked and everything else is UNCHECKED.

B. Still on step 3, MAKE SURE AUDIO BACKEND IS -NOT- set as default but set it to "OpenAL"

C. Depending on what you are targeting, what OS version worked for us was API: Level 7 or Android 2.1-update1

OTHER NOTES: Make sure your shiva STK filename has only letters and underscores...ANYTHING ELSE WILL CAUSE A COMPILE FAIL!

4. ALSO For document saving, android is different. Try this (We use this to check between iOS/Windows and Android:

Code: Select all
        -- sName is the filename itself
        local sFileLocation = ""

        if application.getCurrentUserEnvironmentVariable ( "sOSType" ) == "ANDROID" then
            sFileLocation = "file://"..system.getHomeDirectory ( ).."/Documents/"..sName
        else
            sFileLocation = "file://"..system.getDocumentsDirectory ( ).."/"..sName
        end



Ok so there you have it, thats what we did and it created a new version for android that WORKS EXACTLY THE SAME!!! :) (Well 99% the same, still a few world co-ordinate glitches, but once again its just going into the code and detecting for Android and changing those specific items, but its not a big deal)

Nav
Game Scorpion Inc. http://www.gamescorpion.com
JOIN MY TRAINING AND APP RESOURCE MEGA SITE - App Dev Toolkit (The #1 Resource For App Developers):
http://www.AppDevToolkit.com
User avatar
gamescorpion
Platinum Boarder
Platinum Boarder
 
Posts: 656
Location: Ontario, Canada

Re: noob FAQ - Problem and Answers Only Pls

Postby DoctorPepper » 09 Oct 2011, 22:12

ISSUE:
Scene, Attribute and other editor's or viewers are absent when starting Shiva 3d on 64 bit Windows 7
.

OUR SOLUTION:

Launch Shiva3d in administrator mode.



ISSUE:
When i import my model from ultimate unwrap, it is rotated and gives issues with Click and Go code. I also want to change the scale
.

OUR SOLUTION:

When importing the model from Ultimate Unwrap, change rotation in the import window to 0,-90,90. If you scale, you have to use the same scale for your animation clips. When replacing animation clips, its best to import under a different name and remove the originals
User avatar
DoctorPepper
Platinum Boarder
Platinum Boarder
 
Posts: 469
Location: Belgium

PreviousNext

Return to Getting Started