Topic:   Exception?   (Read 20897 times)


0 Members and 3 Guests are viewing this topic.

GMG Hendo


  • GMG-er

  • **


  • Posts: 155

  • [WITTY TEXT GOES HERE]
Re: Exception?
« Reply #15 on: June 26, 2009, 09:52:39 PM »
Yeah arrays can be confusing at first but they're dead useful when you get a handle on them

GMG Mike


  • Administrator

  • GMG-er

  • *****

  • no avatar

  • Posts: 536
    • mikerichardson.name
Re: Exception?
« Reply #16 on: June 26, 2009, 11:03:46 PM »
Quote
Whoops, you beat me to it, but I have a question also, how are arrays saved to a file?

You could just write one line with the number of elements using COUNTARRAY and then one item per line.

Xiphos


  • GMG-er

  • **


  • Posts: 676
Re: Exception?
« Reply #17 on: June 28, 2009, 10:04:09 AM »

Quote
Its a variable that can hold more than one value.
Say you have an amount of gold you win after each level of fighting. First you'd create the array
 
DIM goldAmount(50)
 
(50) means there are 50 slots within the variable goldAmount, you could use this as each level.
 
Then you'd assign a value to each slot:
 
LET goldAmount(1)=10
LET goldAmount(2)=15
LET goldAmount(3)=20
LET goldAmount(4)=25
etc...
 
So when you beat level one, you get 10 gold, level two, 15 gold and so on.
 
LET level=3
LET playerGold=playerGold+goldAmount(level)
 
 
Whoops, you beat me to it, but I have a question also, how are arrays saved to a file?

What if you wanted to do the opposite? When you get a certain amount of XP you gain a level?

HarryCaray


  • GMG-er

  • **


  • Posts: 119

  • I love YaBB 1G - SP1!
Re: Exception?
« Reply #18 on: June 28, 2009, 10:47:13 AM »
Code: [Select]
DIM xpLevel(50)//Just for the example the maximum level is 50
LET xpLevel(1)=0//At level "1", you need at least 0 xp
LET xpLevel(2)=100//At level "2", you need at least 100 xp
LET xpLevel(3)=500
etc...

Then, you'd check the xp every time you gain it.

LET temp=MAX(playerXP, xpLevel(playerLevel+1)//See which is higher, the player's xp or the next xp level
IF temp=xpLevel(playerLevel+1) THEN//This means the player has not reached the next level yet
NOTEALERT "You have not reached the next level as of yet!", "Sorry!"
ELSE
LET playerLevel=playerLevel+1//The player has more xp than the next level, so he gets to gain a level
END IF

I think this should work.
« Last Edit: June 28, 2009, 10:48:29 AM by HarryCaray »

Xiphos


  • GMG-er

  • **


  • Posts: 676
Re: Exception?
« Reply #19 on: June 28, 2009, 10:59:14 AM »
Thanks Harry!!!

Connors


  • ^ This guy is amazing.

  • ****


  • Posts: 2374

  • It's a secret to everyone...
Re: Exception?
« Reply #20 on: February 23, 2010, 10:47:01 PM »
This is cool, I think this might help with a program I was trying to make.
I'm curious, since an array is basically a list of numbers, can you use it to do something to multiple sprites? For example, if you have a list for all the enemies' numbers called enemies and then say CREATESPRITE (enemies) will it make more than one?
Warning: The above post may have been modified multiple times.

"In a great game, the character must never perfectly obey the user's command"
 - Tim Rogers

http://connorspuzzles.tumblr.com/

Xiphos


  • GMG-er

  • **


  • Posts: 676
Re: Exception?
« Reply #21 on: February 24, 2010, 07:29:35 AM »
Code: [Select]
FOR x = 1 to enemies
IF spritevalid(x)=true THEN
Pushsprite x, -5, 0
END IF
NEXT

Not sure if arrays would but that would push them all.

EDIT: also put a make sure the sprites are valid.
« Last Edit: February 24, 2010, 07:33:09 AM by Xiphos »

EqwanoX


  • Administrator

  • GMG Extraordinaire

  • *****


  • Posts: 1180
Re: Exception?
« Reply #22 on: February 24, 2010, 10:22:42 AM »
**arrays allow you to use variables IN a variables name.**

heres an example of what arrays can do, say your doing an rpg with four enemies. without arrays you have to find the specific enemies hp variable to alter when you attack


if attackenemy=1 then let enemyHP1=enemyhp1-damage
if attackenemy=2 then let enemyHP2=enemyhp2-damage
if attackenemy=3 then let enemyHP3=enemyhp3-damage
if attackenemy=4 then let enemyHP4=enemyhp4-damage

with arrays you dont need to find it you just put the variable of the enemy your attacking in the name of the enemy's hp variable to match enemy

let enemyhp(attackenemy)=enemyhp(attackenemy)-damage

Connors


  • ^ This guy is amazing.

  • ****


  • Posts: 2374

  • It's a secret to everyone...
Re: Exception?
« Reply #23 on: February 24, 2010, 03:41:45 PM »
Thanks guys, that clears thigns up a lot. ;D
 BTW, SOMEONE need to post a tutorial on that SC Wiki for these things, it's kind of empty...
Warning: The above post may have been modified multiple times.

"In a great game, the character must never perfectly obey the user's command"
 - Tim Rogers

http://connorspuzzles.tumblr.com/

Connors


  • ^ This guy is amazing.

  • ****


  • Posts: 2374

  • It's a secret to everyone...
Re: Exception?
« Reply #24 on: February 26, 2010, 08:26:12 PM »
IF spritevalid(x)=true THEN

There's what i was looking for... That's a useful command. XD
(I've been trying to remember where I saw it posted)
Warning: The above post may have been modified multiple times.

"In a great game, the character must never perfectly obey the user's command"
 - Tim Rogers

http://connorspuzzles.tumblr.com/

EqwanoX


  • Administrator

  • GMG Extraordinaire

  • *****


  • Posts: 1180
Re: Exception?
« Reply #25 on: February 27, 2010, 09:49:32 AM »
it might be good to download sc 1.5 for syntax explanations, it uses all the same commands
« Last Edit: February 27, 2010, 09:50:05 AM by EqwanoX »