Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Read In Variable names?

Author
Message
Jonk
19
Years of Service
User Offline
Joined: 31st Jul 2005
Location: East of Java
Posted: 5th Sep 2005 20:03
Got a bit stuck with my game, trying to make a FPS with a few monsters on each level got quite far but my program is getting quite large becuase im not very good at optimizing my code take a look at my routine for collison checking and you'l see what i mean.



Is there any way I can read in some of my variables names in a for next loop using read and data commands. Or maybe use an array or somthing I would be very grateful for any ideas

I tryed somthing like that but it did not work

Me!
19
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 5th Sep 2005 21:03
you can almost directly rephrase that code to work with arrays, eg


if smackobjectplayer=20 and knightdead=0 and myenemy1dead=0 and myenemy1distance <75
DeductPlayer1Health()
smackobjectplayer=0
if object playing(Alien1)=0
SET OBJECT SPEED Alien1,30
play object Alien1,86,110
endif
endif

would start with dim alien(10):dim myenemydead(10):dim myenemydistance(10) for example and then you do

for i=1 to 10
if smackobjectplayer=20 and knightdead=0 and myenemydead(i)=0 and myenemydistance(i) <75
DeductPlayer1Health()
smackobjectplayer=0
if object playing(Alien(i))=0
SET OBJECT SPEED Alien(i),30
play object Alien(i),86,110
endif
endif
next i

thats just an example, just use the array values as you would normal variables but you can alter their index to alter lots of variables from inside a loop.



the average IQ is 100...but the people that took the test where trying to look smart. most people don`t go over 50.
Area 51?, I`m more intrested in what they have in areas 1 to 50
Jonk
19
Years of Service
User Offline
Joined: 31st Jul 2005
Location: East of Java
Posted: 6th Sep 2005 01:29
Hey Thanks a lot you've just made my program about half the size so simple when you know how.

thanks again

Jonk
19
Years of Service
User Offline
Joined: 31st Jul 2005
Location: East of Java
Posted: 6th Sep 2005 02:22
Hmmm one more question can you turn the array into globals so they will work in functions eg:-

global alien(10)
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 10th Sep 2005 05:53
You didn't say whether you were a DBC or DBP user.

In DBC, arrays are global. However, in DBP, there is now a Global command I believe which means that arrays may not now be global.

I'm sure someone will confirm this...

TDK_Man

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Sep 2005 06:47
Dimentionalizing arrays are automatically global in Pro... but there are several bugs.

Outside of a function using "local" before a dim statment does not make it "local" to only outside of functions... inside functions using "local" works right.

Dim's inside functions (without local in front) are still global outside of the function.

I'm pretty sure these are known bugs in the bug reports area.

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 10th Sep 2005 13:58
dbp arrays defined in the main code module are global to the application. arrys defined in code modules are global to that code module

DBP Plugins | EZ_Serv 1.5 Bush, a retard, son of an *sshole
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 10th Sep 2005 15:49
OK thanks for that!

So basically no change in DBP from how it is in DBC with regards to arrays then...

TDK_Man

Jonk
19
Years of Service
User Offline
Joined: 31st Jul 2005
Location: East of Java
Posted: 10th Sep 2005 21:02
Hmmm all useful stuff thanks for that but am having a strange problem with a simple read statement now in the same program
this code should should put 2 palms at the given co-ords defined in the data statment but for some reason there both near the 0,0 co-ords
what am I doing wrong?



oh I am using DBP by the way
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 11th Sep 2005 04:35
You are only reading the first data item each time around the loop.

So, the first object (5) will be at 0,0,0 as you don't position it anywhere else.

The second should be placed at 1870,1870,1870 and the third at 90,90,90. Maybe you are seeing the first and third, while the other is way up in the air somewhere!

What you need is 3 reads per loop so all 6 co-ords are read in:



TDK_Man

Jonk
19
Years of Service
User Offline
Joined: 31st Jul 2005
Location: East of Java
Posted: 11th Sep 2005 05:08
That seems to have done the trick.

Hey thanks TDK_Man sorry for being such a noob but have only just started programming am slowly getting the hang of it though.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 11th Sep 2005 05:37
NP - everyone starts somewhere!

TDK_Man

Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 11th Sep 2005 21:11
Never worry Jonk, you are a much better newbie than many by far. Feel proud !

Login to post a reply

Server time is: 2024-11-27 18:38:57
Your offset time is: 2024-11-27 18:38:57