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.

DarkBASIC Professional Discussion / Something wrong with my UDT

Author
Message
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 25th Jun 2010 16:57 Edited at: 25th Jun 2010 17:01
Hi all,

I'm having trouble with something.

I made a UDT:



And I'm trying to call it later in the code with this:



But for some reason it doesn't work. The object doesn't move or anything. The UDT is only used for this and this only so nothing else should affect it. I'm sure I done this right. Because I used a similar method for another object in my code and it works. But this one doesn't.

Am I missing something here?
BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 25th Jun 2010 17:06
You can't assign values inside the type declaration like that.

See this:


DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 25th Jun 2010 17:18 Edited at: 25th Jun 2010 17:21
Really?

But I have these and they work:



As you can see, "speed" begins as 0. Then in the IF statement, I assigned it a value of -0.3. In the code, this caused my object to first move downwards before moving upwards. If I were to comment out this line:



The object just moves upwards the moment object 101 collides with it.

I don't know... perhaps I'm really not understanding it o.O

EDIT: Wait... are you talking about declaring the values inside the TYPE and ENDTYPE lines? Your example did the same no? I'm confused =/
BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 25th Jun 2010 17:31 Edited at: 25th Jun 2010 17:31
You can set them just fine after defining the variable like that, for example:
myvar.speed = -0.3

You just can't set the value within the type declaration:
type mytype
speed as float = -0.3
stuff as integer = 0
endtype


No matter what you put there, the different parts of the type all start with values of 0.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Jun 2010 17:36 Edited at: 25th Jun 2010 17:37
[Edit BMacZero beat me to it. ]

He's telling you that the values you tried to use inside the type declaration are ignored - they are all set to zero as usual (which, incidentally, is why your second code seems to work).

Did you run his code?

You should just declare your types like this:



then add some code to initialise the variables to the values you want. A UDT is a type not a variable.
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 25th Jun 2010 18:01 Edited at: 25th Jun 2010 18:02
Oh!!! I see...

The code is working no, thanks a lot BMacZero ^^

@GreenGandalf

Yeah, that's exactly what I did. I made sure none of the varibales inside the type are defined. They have no "=" anymore at the end of them =)
BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 25th Jun 2010 18:21
Exactly .

Login to post a reply

Server time is: 2026-07-25 08:30:08
Your offset time is: 2026-07-25 08:30:08