OH no! i'm making a dropdown menu!!

Blitz3D Forums/Blitz3D Beginners Area/OH no! i'm making a dropdown menu!!

Yahfree(Posted 2007) [#1]
Hey, i'm making a dropdown menu function, after i'm done with it, it will be released into the code archive under userinput, this is the second GUI type thing i'v made (see 'Input "Field" ' under user input on CA's)

progress is great, in one day i got most of it done (i'm a newb yes i know)

i have a problem though...

This is what i have so far, im having a problem displaying the options, i'm using types as the options looping thru them and displaying all the "names" of all the objects under that type... and of course making them clickable...

heres my code, tell me what i'm doing wrong, i'm stumped it looks fine to me.. i'v been messing with this for multible hours, still no avail..




Yahfree(Posted 2007) [#2]
Hmm, this works:



but how do i get somthing like the first post to work??


Yahfree(Posted 2007) [#3]
Hmm, this works as well:



but i want it to display a field of multible objects(types)

like the first post...

if you have 4 types:

type1.type = new type
type1\name$="type1"


ect ect..

i want to know how to display those "name" fields in the same way as the working code above?


Ked(Posted 2007) [#4]
This one works more like a WinXP dropdown.




Yahfree(Posted 2007) [#5]
Cool, didnt think about that, I'm still stumped about displaying types... HELP!


b32(Posted 2007) [#6]
I think you need For..Each for that:
For it.Type = Each Type
  Print it\name$
Next



Yahfree(Posted 2007) [#7]
Thats what i thought, tell me whats wrong with the example on the first post...

it uses For...Each

yet it doesnt work, i cant figure out why, any ideas?


DJWoodgate(Posted 2007) [#8]
i


Yahfree(Posted 2007) [#9]
? Yes, i notice the "i" error in the program, but my question more or less is what do i replace that with?


Ben(t)(Posted 2007) [#10]
I can give you a little bit of code that allows you to move the window but it still works when you click the numbers


Yahfree(Posted 2007) [#11]
?


Yahfree(Posted 2007) [#12]
Hmmmmmm this is what i got so far, it still doesnt work! any ideas?:




b32(Posted 2007) [#13]
There is one typo, after "test2.item = new item" it says "test\name" while it should be "test2\name"
And the "For i=1 to 2" loop should be removed. You could increase i yourself during the "For Each item" loop, like this:
i = 0
For namei.item = each item
 i = i + 1
 text etc..etc
Next



Yahfree(Posted 2007) [#14]
That simple eh? HOW ON EARTH DID I MISS THAT?!?!?!!


Thanks!


Yahfree(Posted 2007) [#15]
Well, heres a good question, how would you go about making a scroll-bar if the number of "options" is too much for the box?

i'll mess with it, at least i got a prototype going!


b32(Posted 2007) [#16]
Well, maybe you could try the ViewPort command. Everything that is outside the defined viewport will not be drawn.
ViewPort 100, 100, 100, 200
..draw box..
ViewPort 0, 0, graphicswidth(), graphicsheight()


Yahfree(Posted 2007) [#17]
WOW, thats a neat little command, i'll mess with it, it looks to be just what i need.


Yahfree(Posted 2007) [#18]
Hmm, the scroll-bar is starting to work, but i notice one little strange bug, let me know if you have a fix for it.


my code:


Notice how after "test9" the text seems to lagg behind the rest... test 10 - thru - 12, are laggying behind the ones ontop of it..

any ideas?


b32(Posted 2007) [#19]
Move the section that is labelled ;scroll bar code outside the For..Each loop. Now the scrollbar is updated while the items are being drawn, causing the lag.
And I think you can move the ViewPort commands outside the loop as well, put one of them right before the loop, and the other one after it. But that shouldn't make a big difference, in the long run it might be faster.


Yahfree(Posted 2007) [#20]
Thanks at the moment i'm trying to figure out how to move the text faster then the scrollbar is being moved (like when i have alot of text in there)

got any advice?


Trader3564(Posted 2007) [#21]
nice! but why you don't use a pre-made GUI or do you make your own?


Yahfree(Posted 2007) [#22]
I like to understand on how things work (sounds wierd) but yeah. the best way to learn how they work is make it yourself :)

plus its fun, this is going into a calculator thingy i'm working on.


Yahfree(Posted 2007) [#23]
ok, at the moment i'm working on a system: the more "types" it reads off the faster scrolling speed it has, so it compensates for having more text:



everything works good, now: Change the amount of "items" the top item creating loop makes.. and watch the error..

How do i solve this?


b32(Posted 2007) [#24]
It seems to be working quite allright? Do you mean, that the list items don't 'fit' ?
It is caused by the conversion from 'scrolly' to 'shown'. It should be like this:
shown = 50 - (scrollbarpos * listsize / scrollbarmax)

Scrolly is in the range 70..230, easiest is to make it start from zero, so substract 70 from it:
ScrollbarPos = ScrollY - 70
ScrollbarMax = 230 - 70

The list length is the number of items * 20, but it is nicer to leave 9 items (max. visible) in view when scrolled down completely, so substract (9*20) from it:
ListSize = (i - 9) * 20


Yahfree(Posted 2007) [#25]
hmm, i don't think i get it, could you replace some of the veriables with names of veriables that i use? so i can figure what is what? i don't think i even have a "ScrollbarMax" type thing

Edit: and my problem is.. that the "scrollspeed#=i/8.38" and "shown=120+scrollspeed*70-70-scrolly*scrollspeed"

The basic idea is that every "8.38" loops add 1 to the veriable "Scrollspeed" then i multiply this number on how greater the text moves compared to the scrollbar .. Everytime "i" loops it means 1 more type is there.. so every 8.38 loops, the text should scroll faster

All this works, but the problem is i have make a different number (8.38 for 200 types) for different amount of types

any ideas?


b32(Posted 2007) [#26]
But I did use your variables ? Replace the part that says:
;190 for *2
shown=120+scrollspeed*70-70-scrolly*scrollspeed

with this:
ScrollbarPos = ScrollY - 70
ScrollbarMax = 230 - 70
ListSize = (i - 9) * 20 
shown = 50 - (scrollbarpos * listsize / scrollbarmax)



Fey(Posted 2007) [#27]
No, he made ScollbarMax in order to better define your
shown=120+scrollspeed*70-70-scrolly*scrollspeed
It looks like it'll probably work to me (but I'm knew to all of this). You should be able to just replace the old line with his 4 lines.


Yahfree(Posted 2007) [#28]
Doh, Sorry about that, i see it now.

Thanks!!


Yahfree(Posted 2007) [#29]
Say, is there a way to pass a type thru a function?

like so:

type item
field blah
end type

test(item)

;---

Function test(typename)

for test.typename = each typename
next

end function



b32(Posted 2007) [#30]
No, I don't believe that is possible. You could however use this:

But that is different from what you mean.
What do you need it for ? Maybe there is a better way of doing it. You could for instance use a single type:



Yahfree(Posted 2007) [#31]
Well i'm making a function , trying to make it as portable and reuseable as possible..

the idea is.. the user makes a type, and then the drop down menu will tkae the fed type and read off all of the options in it, like the dropdown menu examples above..

i want the user to be able to feed a type name into the function, then the For...Each loop in the function will read off all the strings in the type, these strings will be selectable,

one they are selected, the main string that the function returns is filled with the selected string..

then this return string can be used..

thats what i want to do, unless theres a better way to do this.


b32(Posted 2007) [#32]
Well, then I would take the 2nd example, and change the \itemkind field into a string. The string can be used to classify items, so you can determine for each item in the typelist, to which (sub)list it belongs. Sort of like this:



Yahfree(Posted 2007) [#33]
interesting... i'll mess with that, Thanks!


Yahfree(Posted 2007) [#34]
is there a limit to how many If statments can be in a if statment?


Yahfree(Posted 2007) [#35]
Oi, Problem..

Why does it not change "dropdown" when this is clicked?




i narrowed it down by blocking out everything else that doesnt have to do with the clicking working..

why does this example not work?

Thanks,
Yahfree


b32(Posted 2007) [#36]
Maybe the main loop needs a 'Flip' ? Because the buffer is set to BackBuffer()


Yahfree(Posted 2007) [#37]
That works, but why doesnt it toggle it? (click it, if its open close, if its closed, open)

Edit: this is wierd, its like it doesnt update, the scrollbar doesnt work, the collisions with the texts doesnt work, it won't close back up when pressed again..

its in the main loop...


b32(Posted 2007) [#38]
First, add a CLS to the loop. Then, add the line:
Global drawdrop
to the start of the program, to make 'drawdrop' a global variable. Else, it is cleared after the 'End Function' command, so it will be zero every time the function starts.


Yahfree(Posted 2007) [#39]
Doh, i missed that..

hey i'm trying to dress this up with a "InitDropDown()" function, that has "Global drawdrop=false,shown=50,scrolly=70"

but it gives me a error, "Global can only appear in main program"

anyway around this? or do i have to deal with it?


big10p(Posted 2007) [#40]
Just declare the Globals in the main code, then you can set them to whatever in the function.


Yahfree(Posted 2007) [#41]
k, Also i have to make a few of those global veriables equal to some info i feed into the function..

like:
function blahblah(x)

end function

global Shown=x

while not keyhit(1)
blahblah(100)
flip
wend
end


theirfore Shown=100?

possible or not?


big10p(Posted 2007) [#42]
No. x doesnt have scope outside the function. Just put Shown = x inside the function.


Yahfree(Posted 2007) [#43]
but then i have the problem of it constantly replacing itself in the main loop thats why i made the global veriables in the first place


big10p(Posted 2007) [#44]
Sorry, I'm lost as to what you're trying to do.


Yahfree(Posted 2007) [#45]
i have a veriable, that keeps track of where to draw the scrollbar part of the menu.

if i don't declare it before the main loop it keeps resetting itself, EG the scrollbar won't move.

but, the functions in the main loop.

and the veriable must equal somthing you feed into the function.

so i need somthing that can get info from somthing you feed into the function, outside the function.

any ideas?


big10p(Posted 2007) [#46]
and the veriable must equal somthing you feed into the function.
So, why doesn't setting the global variable inside the function work?


Yahfree(Posted 2007) [#47]
Because it has to be able to change, and because the function is in the main loop, if i declare it in the function, then it keeps resetting itself


Yahfree(Posted 2007) [#48]
thats why i was thinking of a InitDropDown function.. where you can feed the x/y into that and declare the globals in there. but no, no globaling outside the main prog


Yahfree(Posted 2007) [#49]
But again that method above would take away being able to use the function more then once i think..

HELP!


Yahfree(Posted 2007) [#50]
this is a brick wall, i cant make this reuseable if this doesnt work, thats the whole point :\

I'll keep messing with it.. any of you more experienced people have an idea?


b32(Posted 2007) [#51]
You can make the variables global, and then initialize them in the function:
Global x

Function Init()
 x = 3
End Function

Else, you could make a variable called init and set it to one after the variables are set:
Global init

Function DrawStuff()
  If init = 0 then x = 3: init = 1
End Function


The best way to proceed however from here is turning your DropDown gadget into a type, then create a function that creates the DropDown, and another function that draws it.


Yahfree(Posted 2007) [#52]
I like the second one.. but i gave it a go and it didnt work:




b32(Posted 2007) [#53]
The line 'Global InitDD' should be placed before the function. Also, some other vars. should be global, too:



Yahfree(Posted 2007) [#54]
Very nice, ok, now that its working nicely i'm now working on making it work with multible drodowns..

i ran into a problem, it doesnt seem to work for some reason, any ideas? it looks alright to me..



Also, i tried modifing your "more objects = faster scrolling" code, with little success, it seems to get wierder if the box is placed deeper on the "Y" axis..

------------
EDIT: I looked at your code deeper, and i fixed the problem with the faster scrolling ect.. still need help with the multible dropdown support though..
----------

any ideas?

by the way, thanks for putting up with me lol..


Yahfree(Posted 2007) [#55]
HMM, i think the problem is the functions are relying on the same veribs, i tried this:

Global InitDD,drawdrop,scrolly,shown,used=0

Global NO_OF_DDS=2


and this in the function:

If used<NO_OF_DDS
drawdrop=False
scrolly=y+20
shown=x
used=used+1
End If

If used > NO_OF_DDS
used=0
End If



no success... Any ideas?


b32(Posted 2007) [#56]
I think the best approach is using a type to store the variables for each dropdown. That way you can create as many as you like. It is probably the best to calculate 'shown' at the start of the function, before drawing anything.
That way it doesn't need to be stored. The Type should contain all variables that are required outside the funciton: drawdrop, scrolly and words$.

I would write a function that creates (and initializes) the dropdown, and use the function that you have to draw the dropdown.

Then, in your main loop, you can do this to write the dropdowns:
For dropdown = Each TDropDown
DrawDropDown dropdown
Next

Later on, you could maybe write a function to dispose the dropdowns again, and a function that adds items to a specific dropdown.

If you are going to use MouseX/Y and MouseHit more than once, it is best to store them into (global) variables. MouseHit can only be read once and MouseXY can be different every time you read them.


Yahfree(Posted 2007) [#57]
hmm, could you give me a small example, on where these would be placed?


b32(Posted 2007) [#58]
Do you mean the mouse stuff ? Or the types ?
About the mouse, I meant something like this:



Yahfree(Posted 2007) [#59]
The types, i'v been messing with it, i'm still a bit new to types if you would give me a example that would be awsome.


Thanks for the MouseX/Y ect that makes sense


b32(Posted 2007) [#60]
I don't know if this example is best, but it shows the idea. It uses a type to store buttons:



Yahfree(Posted 2007) [#61]
i'll mess with it, Thanks.


Yahfree(Posted 2007) [#62]
Hmm, i took some time to mess with it, it looks like this is the right direction, but for the life of me i cant figure out whats wrong with this:




i get a MAV error, thats a first.. but thats the right direction?

Any ideas?


b32(Posted 2007) [#63]
Yes, it is going allright. The MAV is an 'object doesn't exist' error. To see the right error message, enable debug.
Now, the first two times CreateDropDown is called, 'b.dd' exists. However, after two times, it isn't created anymore.

I think it is best to split CreateDropDown into CreateDropDown and DrawDropDown.

The CreateDropDown$() can be mostly the same. Right after the If-block "If InitDD > 2 etc .. End If", add an End Function.
The rest of the function could become DrawDropDown.
The DrawDropDown$() function then should take "b.dd" as a parameter:
Function DrawDropDown$(b.dd)


Right after that, read everything you need for the function from the type:
x = b\x
y = b\y
shown = b\shown
etc.

Everything that needs to be relative to a certain dragdrop, should be in the type.

When the function is done, store everything that has changed, back into the type:
b\x = x
b\y = y
etc.
End Function


The order should be this:
1) create dragdrops with CreateDragDrop. There is no need for the InitDD variable.
2) add items
3) calculate length for each dragdrop (b\listsize)
4) in mainloop, call DrawDragDrop() that does this:
move scrollbar
calculate 'shown'
draw dragdrops
respond to mouseclick


Yahfree(Posted 2007) [#64]
So CreateDropDown should hold the inits create the types ect, while DrawDropDown handles the drawing, if statments loops (basicly almost the whole thing)..

I'll mess with it, Thanks!


Yahfree(Posted 2007) [#65]
Hmm, it still gives me a MAV error:




b32(Posted 2007) [#66]
It is again an 'object does not exist' error. In bb, goto Program->Debug Enabled? Else, every error is a MAV, which can be very confusing.
The reason for the error is this:
blah$=DrawDropDown$(blah$,1,b.dd)
blah2$=DrawDropDown$(words$,2,b.dd)

When these lines are executed, 'b.dd' does not exist.
Instead use this:
For b.dd = Each dd
blah$=DrawDropDown$(blah$,1,b.dd)
Next

This way, all 'dd's are drawn.
Then, at the end of the DrawDropDown() function, add the line:
b\drawdrop = drawdrop

So the drawdrop mode is stored for each dd when the function ends.
Then, in CreateDropDown, add:
b\x=x
b\y=y

And add an x and y field to the 'dd' type. Finally, add:
x=b\x
y=b\y

To the start of the function. Else, all dropdowns are drawn in the same place.


Yahfree(Posted 2007) [#67]
Ok, awsome, this is starting to look like its working, one small problem, i'm having the problem of it resetting itself again, i tried the Init dropdown, but it doesnt work, because thats only for 1..

Could you point me in the right direction?

Also Thank you so much for all the help, esp. teaching me types in depth..


b32(Posted 2007) [#68]
:) np, I'm glad I can help out. At the end of the drawing function, add:
b\scrolly = scrolly

If you want to set the labels individually, do the same thing for words$:
At the start of the function use:
words$ = b\words$

And at the end, use:
b\words$ = words$

instead of "return words$"


Yahfree(Posted 2007) [#69]
I don't think i was clear, heres some code:


It keeps resetting, any ideas?


b32(Posted 2007) [#70]
When I ran this example, it didn't respond at all ? It seemed that it needed "Global CursorX, CursorY, CursorHit" at the start of the program.
In the For Each..Next loop that draws the dd's, you only need one DrawDropDown command. The For..Next loop ensures that all dd's are drawn. If you draw them twice, they open and then close again in the same loop.


Yahfree(Posted 2007) [#71]
but if i only write one DrawDropDown, how do i get the other one to get its own words? hmm... Also it looks like the scrollbars arent working... any ideas?

Edit heres the new example, sorry about the other one it all didnt get copyed :)




b32(Posted 2007) [#72]
That is just a typo in the line:
b\shown = 10 - (scrollbarpos * listsize / scrollbarmax)

It should be "shown = 10 etc" (without the b\)

If you want each scrollbar to be able to have it's own words$, add that as a field to the dd type.
In the function DrawDropDown$(), you can leave out the words$ parameter, and use the words$ that is stored in the type:
words$ = b\words$

When the function ends, you can store words$ back into the type:
b\words$ = words$



Yahfree(Posted 2007) [#73]
What about the stuff that goes into the drop down.. see the "number" param.. i give the list types their own number or id. so i can pick what goes into the dropdown... i cant choose a number for each drop down if i only call drawdropdown only once


Yahfree(Posted 2007) [#74]
This is really coming togetther now :), brings a smile to my face having 4 dropdowns and having them work perfectly... :D .. After the problem above is solved i think this is about done, Huge Thanks to you B23..

How long have you been programming? you have to have at least a few years, you seem to know the answer to all my questions : \

though i feel bad i cant help you with one of your questions.


b32(Posted 2007) [#75]
For 21 years .. I started when I was 8, which was .. erm in 1814, during WWI. It were tuff times: we had no food, so we had to eat our C64 tapes to survive. We made 'Terrys Big Burger' and 'Giana soup' .. sigh ..
I really like to help out. My friends can't write programs -at all- and I want to talk about it with people. That is why I appreciate the forums so much.
But have you solved the id thing then ? You need to pass the 'number' parameter to CreateDropDown function, instead of the DrawDropDown, and make a field that contains the number.
Then, in DrawDropDown, use:
number = b\number


Yahfree(Posted 2007) [#76]
alright, Yeah, i'm still young (14) still learning, dabbing in C++, ect, but yeah, i also have another problem, i'm trying to give these dropdowns an ID, so i can then say "if id=1 then display this ones current picked item"

so i tried this in the creation process:
Function CreateDropDown(x,y)

b.dd = New dd
b\x=x
b\y=y
b\drawdrop=False
b\scrolly=y+20
b\shown=y
b\num=num2

num2=num2+1

End Function


and this to display:

For b.dd = Each dd
If b\num=1 Text 0,0,"DropDown 1: "+b\words
If b\num=2 Text 0,0,"DropDown 2: "+b\words
Next


No workie :(

Edit: and i know how you feel, my friends think its wierd to program, because they cant understand it :D, but they like trying stuff i made, i love it when they say: yeah right, you didnt make that...

then ofcourse i have no proof but oh well :\


b32(Posted 2007) [#77]
Hmm, it seems like it should work. Is num2 global ? Else, all dropdowns will get the same id.
edit: and num2 starts off at zero, so the id's will be: 0, 1


Yahfree(Posted 2007) [#78]
Doh, That worked, Thank you B32 if i don't run into any problems, i should have this done very soon :D


Yahfree(Posted 2007) [#79]
I created a function to delete dropdowns by ID:

Function DeleteDropDown(ID)
For FindDD.DropDown = Each DropDown
If FindDD\DropDown_ID=ID Delete FindDD
Next
End Function


This works find, tested and confirmed, but, i wanted to use this to delete and recreate a dropdown, again and again, incase somthing changes.

like so:

For CheckDD.DropDown = Each DropDown
If CheckDD\words="test1" Catagory=1
If CheckDD\words="test2" Catagory=2
Next

Select Catagory
Case 1
DeleteDropDown(2)
CreateDropDown(350,120,2)
Case 2
DeleteDropDown(2)
CreateDropDown(350,120,3)
End Select


but somthing doesnt work, it seems to lagg, or somthing, because it doesnt work half the time, any ideas?


b32(Posted 2007) [#80]
In the Select..Case, in both case 1&2, you are deleting dropdown(2), is that right ?
\words and 'Catagory' are never reset, so if this code is executed in a loop, and the dragdrop is set to, say, 'test1', it will keep on deleting and creating the dropdowns until Catagory is reset and \words$ is no longer "test1"/"test2"
I think that is causing the lag.


Yahfree(Posted 2007) [#81]
Hmm, heres a bigger chunk of code to look at.. i don't think its deletedropdown, because you saw how it works, it deletes by the dropdowns id, not the list id..

the example above, should say, if you select this in another dropdown the other dropdown will be erased and rewrittin with a new list id...

but, it looks like its constantly deleting/rewriting every loop, i don't want this, i only want it to delete/rewrite if Catagory changes (once)

like:

2 drop downs.

a user selects somthing out of the first dropdown

the second dropdown changes whats in it, (deletes/rewrites ONCE)

user selects somthing else out of the first dropdown,

the second dropdown changes again (deletes rewrites ONCE)

in the code above it seems like its deleting and rewriting everyloop, any ideas?


b32(Posted 2007) [#82]
To do that, you should reset \words$ and Catagory:
Catagory=0
For CheckDD.DropDown = Each DropDown
If CheckDD\words="test1" Catagory=1: CheckDD\words$=""
If CheckDD\words="test2" Catagory=2: CheckDD\words$=""
Next



Yahfree(Posted 2007) [#83]
still laggs

heres the updated code (in the main loop)
Catagory=0
For CheckDD.DropDown = Each DropDown
If CheckDD\DropDown_ID=1 And CheckDD\words="test1" Catagory=1
If CheckDD\DropDown_ID=1 And CheckDD\words="test2" Catagory=2
Next

Select Catagory
Case 1
DeleteDropDown(2)
CreateDropDown(350,120,2)
Case 2
DeleteDropDown(2)
CreateDropDown(350,120,3)
End Select


also anything wrong with my deleting method?
Function DeleteDropDown(ID)
For FindDD.DropDown = Each DropDown
If FindDD\DropDown_ID=ID Delete FindDD
Next
End Function



Edit: Hmm, mabye a Do once if catagory changes type deal would work?

like so:

;Catagory=0
For CheckDD.DropDown = Each DropDown
If CheckDD\DropDown_ID=1 And CheckDD\words="HybridTurrs" Catagory=1
If CheckDD\DropDown_ID=1 And CheckDD\words="EnergyTurrs" Catagory=2
Next

If Catagory <> Catagory doOnce=0

If doOnce=0
Select Catagory
Case 1
DeleteDropDown(2)
CreateDropDown(350,120,2)
Case 2
DeleteDropDown(2)
CreateDropDown(350,120,3)
End Select
doOnce=1
End If

For DrawDrops.DropDown = Each DropDown
DrawDropDowns(DrawDrops.DropDown)
Next


But i don't think thats the correct method of doing that (last i checked the operator "<>" means if it moves?) but the above doesnt work..


b32(Posted 2007) [#84]
Maybe you should delete dropdowns with the type 3 as well ? Because now, you are only deleting type 2 dropdowns:
Catagory=0
For CheckDD.DropDown = Each DropDown
If CheckDD\DropDown_ID=1 And CheckDD\words="test1" Catagory=1: CheckDD\words$=""
If CheckDD\DropDown_ID=1 And CheckDD\words="test2" Catagory=2: CheckDD\words$=""
Next

Select Catagory
Case 1
DeleteDropDown(2)
DeleteDropDown(3)
CreateDropDown(350,120,2)
Case 2
DeleteDropDown(2)
DeleteDropDown(3)
CreateDropDown(350,120,3)
End Select

If it still lags, could you post the entire code? It is much easier for me to see what is wrong that way.


Yahfree(Posted 2007) [#85]
alright,

heres the whole code:


When it prompts you for what "ship" your in type in "test" then click next, you'll see the dropdowns :D

sorry bout the messy code, didnt have time to coment it or make it look pretty


b32(Posted 2007) [#86]
I didn't notice any lag, but I could see that a lot of dropdowns were made.
The trouble is that the 'ID' and 'Accepts' are confused.
In DrawDropDown, Accepts is used, and in both CreateDropDown and DeleteDropDown, the ID is used. This prevents the dropdowns to be deleted after a while.
You still need to change the code:

to stop the program to generate a lot of dropdowns once 'test' or 'test2' is chosen, but also, you should take a look at Accepts vs. ID.


Yahfree(Posted 2007) [#87]
so the main problem here is the way i assign ID's i do them in order of them being created,

i had an idea, to make the id like so:

myid=CreateDropDown(x,y,AcceptedList)

DeleteDropDown(myid)

how would i go about doing somthing like that?

Assigning a name to control the dropdown..


b32(Posted 2007) [#88]
For that, use the 'Return' command at the end of the function.
You can use it to return any value, depending on the type of function.
Say, the function is called CreateDropDown$, then 'return' returns a string.
If the function is called CreateDropDown, it will return an integer. (Officially, there should be a % after it, but it is the default type.)
With a #, the function returns a float, but I suppose either an integer or string should work best for what you want.

You could however, also return the complete dropdown as the result:
Function CreateDropDown.DropDown(blablah)
 b.DropDown = new DropDown
 return b
End function


Then you can use something like this:

FirstDropDown = CreateDropDown(blablah)
..
..
DrawDropDown(FirstDropDown)



Yahfree(Posted 2007) [#89]
i get a Iligal type conversion error... from doing this:

Function CreateDropDown.DropDown(x,y,Accepted)



NewDD.DropDown = New DropDown
NewDD\x=x
NewDD\y=y
NewDD\drawdrop=False
NewDD\scrolly=y+20
NewDD\shown=y
;NewDD\DropDown_ID=ID_Number
NewDD\Accepts=Accepted


;ID_Number=ID_Number+1
Return NewDD
End Function


dd1=CreateDropDown(10,120,1) ;ID=1
dd2=CreateDropDown(350,120,2) ;ID=2


comented out the deleting rewriting code for now, so the error isnt from that


b32(Posted 2007) [#90]
Ow seems I forgot something:
dd1.dropdown=CreateDropDown(10,120,1) ;ID=1
dd2.dropdown=CreateDropDown(350,120,2) ;ID=2

They need to be declared as a dropdown as well.


Yahfree(Posted 2007) [#91]
Interesting, so how would i check stuff with this? i modified the delete function, it seems to work:

Function DeleteDropDown(ID.Dropdown)
Delete ID
End Function


:D

but how do i check stuff with it?
like i did before:
If CheckDD\DropDown_ID=1
If CheckDD\DropDown_ID=1


how do i do it with the new id system?


b32(Posted 2007) [#92]
Well, suppose you created the first dropdown with this:
FirstDropDown.DropDown = CreateDropDown(etc)

Then, later on, you can check the \words$ with:
If FirstDropDown\words$ = "test" Then ..
If FirstDropDown\words$ = "test2" Then ..

Instead of using the For Each..Next loop.


Yahfree(Posted 2007) [#93]
awsome, thanks B23 :D

i'll do some lagg testing in a bit and i'll report back


Yahfree(Posted 2007) [#94]
Cool, i think i might have the nail in the coffen for this..

i need some sort of method of doing somthing only once if something changes.

In this case, if Catagory changes i want it to delete/rewrite the dropdown.. ONCE not every loop.. then if it changes again, Delete and rewrite ONCE again..

heres what i have so far:

If dd1\words="test1" Catagory=1
If dd1\words="test2" Catagory=2


Select Catagory
Case 1
DeleteDropDown(dd2.DropDown)
dd2.DropDown=CreateDropDown(350,120,2)
Case 2
DeleteDropDown(dd2.DropDown)
dd2.DropDown=CreateDropDown(350,120,3)
End Select




For DrawDrops.DropDown = Each DropDown
DrawDropDowns(DrawDrops.DropDown)
Next



b32(Posted 2007) [#95]
So why is it doing that every loop ?


Yahfree(Posted 2007) [#96]
Because that sniplet of code is in the main loop, because it has to be able to change, but its deleting/redrawing every loop


b32(Posted 2007) [#97]
Well, it keeps repeating the same action over and over again, because Catagory, once set to one or two, doesn't change back. So then the next question is -and that one is mory tricky-: why doesn't Catagory change back ?
At first sight, one would say: add the line:
Catagory = 0

before the part:
If dd1\words="test1" Catagory=1
If dd1\words="test2" Catagory=2

But then still, it doesn't change. Why ?
Because dd1\words$ doesn't change back.
So: as long as dd1\words$="test", Catagory will be one, and the second menu will be created and destroyed, over and over again.


Yahfree(Posted 2007) [#98]
I need somthing like this:

Global CatagoryDraw=0
..
..
..
If dd1\words="HybridTurrs" Catagory=1
If dd1\words="EnergyTurrs" Catagory=2


If Catagory <> Catagory CatagoryDraw=0

If CatagoryDraw=0
Select Catagory
Case 1
DeleteDropDown(dd2.DropDown)
dd2.DropDown=CreateDropDown(350,120,2)
Case 2
DeleteDropDown(dd2.DropDown)
dd2.DropDown=CreateDropDown(350,120,3)
End Select
CatagoryDraw=1
End If



For DrawDrops.DropDown = Each DropDown
DrawDropDowns(DrawDrops.DropDown)
Next


Notice the "<>" i thought that is to check if it moves, i guess not, how do i check if somthing changes..?


b32(Posted 2007) [#99]
You could do that by storing Catagory in another variable, for example oldCatagory.
If Catagory <> oldCatagory then
    oldCatagory = Catagory
    ..respond..
End if



Yahfree(Posted 2007) [#100]
What does "<>" do?


b32(Posted 2007) [#101]
It means: unequal to, so it is the reverse of "="

3 = 3
4 <> 3


Yahfree(Posted 2007) [#102]
YAY!!

Perfect....

Edit: DANG! 102 posts on this thread, never knew making a GUI would have this many problems

Thank you B23


b32(Posted 2007) [#103]
No problem. As the Spanish people so beautifully phrase: "El ser programador significa tener una vida de problemas"


Yahfree(Posted 2007) [#104]
uh yeah Thanks!


Yahfree(Posted 2007) [#105]
hmmm, whats wrong with the following statement?

If RectsOverlap(300,350,60,25,MouseX(),MouseY(),10,10) And MouseHit(1) Or KeyHit(28)

For getstats.list = Each list
If getstats\name$=dd2\words$

C_POWER=C_POWER+getstats\pg
C_CPU=C_CPU+getstats\cpu
End If
Next

End If



b32(Posted 2007) [#106]
Nothing really .. Maybe the usage of MouseHit() and Keyhit()? Because they can only be read once each loop. They reset themselves after being read.
Edit: wait .. maybe they should have extra brackets, like this: ... And (MouseHit(1) Or KeyHit(28))


Yahfree(Posted 2007) [#107]
:) duh, that worked, WHY DIDNT I REMEMBER THAT?!?! note to self, always make a ver. to store Mousehit(1)


Yahfree(Posted 2007) [#108]
Well, thats it, its completed, Thank you b23, go check it out, leave a coment:

feel free to improve it or add suggestions :D

http://blitzbasic.com/codearcs/codearcs.php?code=2018


Yo! Wazzup?(Posted 2007) [#109]
b23? I think you mean b32.

EDIT: Maybe you should make one dropdown close when another dropdown opens.


Yahfree(Posted 2007) [#110]
You can do that effect yourself, its easy, just call the DrawDrop attribute of the dropdown and change it..

something like this before the DrawDropDowns() in the main loop:

if dd1\drawdrop=true
dd2\drawdrop=false
dd3\drawdrop=false
..
..
end if


If you have any more questions ask in the code archives


Yo! Wazzup?(Posted 2007) [#111]
I (sorta) knew that, but I didn't exactly know how your code worked, and I didn't really feel like reading through every little bit.